Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with dates 2

Status
Not open for further replies.

Jouster

Programmer
Dec 4, 2000
82
US
Hi,

I would like to know what is the best way to go about getting the time elapsed from a certain date. I would like to get it in the format of year/months/days/hours/minutes. I have been looking at the datediff function but there must be more to it because of leap years and such. If someone could give me a little explanatin on doing this or send me to some information I could read on this I would greatly appreciate it.

Thanks,
-J
 
Store your dates in DateTime objects (part of the .NET framework and not the Visual Basic compatability layer), then subtract them. The result is a TimeSpan object, which can tell you how long the interval was in years, seconds, whatever.
Code:
Dim myDate1 As DateTime
Dim myDate2 As DateTime
Dim myDiff As TimeSpan

myDate1 = new DateTime(2004, 1, 1, 0, 0, 0)
myDate2 = DateTime.Now

myDiff = myDate2 - myDate1
;

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You will find an example on the usage of TimeSpan at the following site:


look under vb.net and the example called Timer Resolution Test.

Happy Programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top