Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 10th, 2005, 8:32 AM   #1
Illuminati
Newbie
 
Join Date: Apr 2005
Posts: 12
Rep Power: 0 Illuminati is on a distinguished road
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?
Illuminati is offline   Reply With Quote
Old Apr 10th, 2005, 5:12 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Apr 10th, 2005, 7:40 PM   #3
Illuminati
Newbie
 
Join Date: Apr 2005
Posts: 12
Rep Power: 0 Illuminati is on a distinguished road
Well it didnt work before, but that appears to work, lol. thanks.
Illuminati is offline   Reply With Quote
Old Apr 10th, 2005, 7:50 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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.
Dameon is offline   Reply With Quote
Old Apr 10th, 2005, 8:33 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:14 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC