Home All Groups Group Topic Archive Search About
Author
5 Jan 2006 8:32 PM
JIM.H.
Hello
I have TextBox1 this keeps date and time information and I need to compare
this DateTime with the current DateTime and find difference in hour. How can
I do this in VB.Net?

Thanks,

Author
5 Jan 2006 9:57 PM
Kevin Spencer
Use the DateTime.Subtract() method. When you subtract a DateTime from
another DateTime, it returns a TimeSpan, from which you can extract any
portion. Example:

DateTime dt = new DateTime(1, 4, 2005, 12, 12, 0);
TimeSpan ts = DateTime.Now.Subtract(dt);
int hours = ts.TotalHours;

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

Show quoteHide quote
"JIM.H." <J***@discussions.microsoft.com> wrote in message
news:22F17159-0525-4536-85A3-EAFBCC7C837D@microsoft.com...
> Hello
> I have TextBox1 this keeps date and time information and I need to compare
> this DateTime with the current DateTime and find difference in hour. How
> can
> I do this in VB.Net?
>
> Thanks,
>

Bookmark and Share