Q: DateTime Difference

G

Guest

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,
 
K

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top