473,414 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Get hours difference between two DateTime vars?

I know I could just get the year,month,day, etc of of each DateTime vars and calc the
hours difference between them. I've done this before in other languages with a
formula for handling leap years. But has someone already done what is necessary to
get the number of seconds or minutes or hours between two DateTimes?

Can one convert to ticks, do a tick difference, and then somehow convert to number of
hours or minutes or seconds that equals?

If so, what is ratio of ticks to some other time unit?
Nov 17 '05 #1
2 10975
Joe
Hi Randall,

Is this what you're looking for?

DateTime start = new DateTime(2000, 1, 31);
TimeSpan ts = DateTime.Now.Subtract(start);

ts.TotalHours;

-Joe

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:e$**************@TK2MSFTNGP12.phx.gbl...
I know I could just get the year,month,day, etc of of each DateTime vars
and calc the hours difference between them. I've done this before in other
languages with a formula for handling leap years. But has someone already
done what is necessary to get the number of seconds or minutes or hours
between two DateTimes?

Can one convert to ticks, do a tick difference, and then somehow convert
to number of hours or minutes or seconds that equals?

If so, what is ratio of ticks to some other time unit?

Nov 17 '05 #2
Joe <jb*******@noemail.noemail> wrote:
Hi Randall,

Is this what you're looking for?

DateTime start = new DateTime(2000, 1, 31);
TimeSpan ts = DateTime.Now.Subtract(start);

ts.TotalHours;


Or even more readably, for the middle line:

TimeSpan ts = DateTime.Now - start;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John McGinty | last post by:
Hello Chaps, Just a little sounding on removing out of hours from some datetime date that I have. Basically we have a helpdesk that logs calls when they are entered and when they are resolved....
26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
2
by: Diogo Alves - Software Developer | last post by:
Hi, I am writing a class to work with a table that I have... I would like to initialize every var that will be used to nulls... I found a problem doing this to DateTime vars How can I add a...
4
by: Vivek Sharma | last post by:
Hi, I need to calculate the time difference between today 2pm and tomorrow 2 am. How do I calculate? Thanks Vivek
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
5
by: Konstantinos Pachopoulos | last post by:
Hi, does any body now any such algorith? to find difference in days from YYYYMMDD to YYYYMMDD? Or just an algorithm, that converts YYYYMMDD to seconds since the epoch? Thanks
5
by: Irfan Mughal | last post by:
i need ur help. i want to have CPU utilization of last 24 hrs. for time being i want to have result from 1 server. select "AVG_%_Total_Processor_Time", "WRITETIME", "MAX_...
3
by: iceone | last post by:
Hi everybody, I am monitoring a call center and i need to calculate the working hours between the moment the call is answered and the moment the call is closed. i need to calculate the working...
3
by: RN1 | last post by:
A Form has 2 TextBoxes where in users enter date & time. Example (in mm/dd/yyyy format): 09/20/2008 17:54 (1st TextBox) 09/29/2008 6:13 (2nd TextBox) How do I find out how much time (in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.