473,320 Members | 1,946 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,320 software developers and data experts.

Time difference

Hi,

I need to calculate the time difference between today 2pm and tomorrow 2 am.
How do I calculate?

Thanks

Vivek
Dec 4 '05 #1
4 3309
You can add and subtract DateTime values and end up with a TimeSpan...
The following code is a very easy representation of how to use it:
DateTime dttoday = DateTime.Now(); // Today's Time
DateTime dttomorrow = DateTime.Now.AddDays(0.5); // 12 hours from now
TimeSpan ts = dttomorrow - dttoday; // Subtract today from "tomorrow"
Debug.WriteLine(ts.TotalHours.ToString()); // Write out hours difference

Vivek Sharma wrote:
Hi,

I need to calculate the time difference between today 2pm and tomorrow 2 am.
How do I calculate?

Thanks

Vivek

Dec 4 '05 #2
Also, Please disregard the () after .Now - I was writing too fast and
not thinking of what i was doing. It should really look like this:

DateTime dttoday = DateTime.Now;
DateTime dttomorrow = DateTime.Now.AddDays(0.5);
TimeSpan ts = dttomorrow - dttoday;
Debug.WriteLine(ts.TotalHours.ToString());
Vivek Sharma wrote:
Hi,

I need to calculate the time difference between today 2pm and tomorrow 2 am.
How do I calculate?

Thanks

Vivek

Dec 4 '05 #3
Thanks for your help... What shall I do in case it let us say 2.45pm and
next day 3.25pm. How do I handle this?

Thanks


"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:u6****************@TK2MSFTNGP10.phx.gbl...
Also, Please disregard the () after .Now - I was writing too fast and not
thinking of what i was doing. It should really look like this:

DateTime dttoday = DateTime.Now;
DateTime dttomorrow = DateTime.Now.AddDays(0.5);
TimeSpan ts = dttomorrow - dttoday;
Debug.WriteLine(ts.TotalHours.ToString());
Vivek Sharma wrote:
Hi,

I need to calculate the time difference between today 2pm and tomorrow 2
am. How do I calculate?

Thanks

Vivek

Dec 5 '05 #4
So the answer would be 24.6 hours right? You can aquire this
information by:

DateTime dttoday = DateTime.Parse(@"12/4/2005 2:45 PM");
DateTime dttomorrow = DateTime.Parse(@"12/5/2005 3:25 PM");
TimeSpan ts = dttomorrow - dttoday;
Debug.WriteLine(ts.Days.ToString() + "Days, " + ts.Hours.ToString() +
"Hours, " + ts.Minutes.ToString() + "Minutes");
Vivek Sharma wrote:
Thanks for your help... What shall I do in case it let us say 2.45pm and
next day 3.25pm. How do I handle this?

Thanks


"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:u6****************@TK2MSFTNGP10.phx.gbl...
Also, Please disregard the () after .Now - I was writing too fast and not
thinking of what i was doing. It should really look like this:

DateTime dttoday = DateTime.Now;
DateTime dttomorrow = DateTime.Now.AddDays(0.5);
TimeSpan ts = dttomorrow - dttoday;
Debug.WriteLine(ts.TotalHours.ToString());
Vivek Sharma wrote:
Hi,

I need to calculate the time difference between today 2pm and tomorrow 2
am. How do I calculate?

Thanks

Vivek


Dec 5 '05 #5

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

Similar topics

2
by: Jason Reljac | last post by:
Howdy, For a project I am working on right now I need to be able to calculate the time difference between to given times. (For example...The difference between 11:30 am and 1:45pm being 2:15) ...
10
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
2
by: Joe User | last post by:
I am looking to calculate the difference between and event time and a sample time of Now. This is the query that I thought would do it, however I'm returning DIFFERENCE values that look the same...
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
6
by: Michael Bulatovich | last post by:
I have a very simple db I use for keeping track of hours, tasks, projects, clients etc. It has a form that I use to enter data. Currently the form has a textbox for a field called "start time",...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
5
by: Geoff Jones | last post by:
Hi I have question regarding times and dates in a datatable. I have one table with one column having the date e.g.03/09/04, and another column other the time 08:03:05. The other table has one...
3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
3
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.