![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 12
Rep Power: 0
![]() |
Time between two dates and times
Need to be able to get the amount of time inbetween 2 dates and times, im storing the date and time in a database using the DateAndTime method.
I need to be able to find out the amount of Days, hours, minutes and seconds from that date and time and the time and date of that day. Ive tried using Datediff() but that only gave me the time between the date and not the time, can anyone help me out? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Why not use DateDiff?
Private Sub Command1_Click()
Dim lngHowLong As Long
lngHowLong = DateDiff("s", "3/3/2002 14:22:55", Now)
MsgBox "There are " & lngHowLong & " seconds between the date shown and now."
End Sub
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 12
Rep Power: 0
![]() |
Well it didnt work before, but that appears to work, lol. thanks.
|
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Personally, I use the built in data types DateTime and TimeSpan and their member functions for this. All you have to do is:
Now.Subtract(TheStartingDate) ..whcih returns a TimeSpan. The TimeSpan class has properties for various (read: all you could want) measurments. So if you wanted all seconds between the two times, you would write: Now.Subtract(TheStartDate).TotalSeconds However, There is a large difference between TotalSeconds and Seconds, and that goes for the others as well. Say you had a TImeSpan of 1 minute and 3 seconds...TotalSeconds would return 63 while Seconds would return 3. TimeSpan has everything from years to milliseconds, so you should be covered. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
You're welcome Illuminati
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|