|
-
May 2nd, 2007, 03:28 AM
#1
Thread Starter
Frenzied Member
Difference between two dates durations
Lets say I have a date and time that is 05-01-07 01:11:11 pm. I have another date and time that is 05-05-07 05:50:55 pm.
How can I find the duration between both dates and times down to the exact seconds?
I would like to get how many days in between and the remaining of hours, minutes and seconds.
So, in this case it would be 4 days and something hour, minutes and seconds.
Thank You
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
May 2nd, 2007, 03:30 AM
#2
Fanatic Member
Re: Difference between two dates durations
DateDiff() should do the trick.
Do a search on this forum for more information.
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
-
May 2nd, 2007, 03:33 AM
#3
Re: Difference between two dates durations
The DateDiff() Function should work.
-
May 2nd, 2007, 04:49 AM
#4
Re: Difference between two dates durations
just for a quick reference
vb Code:
Private Sub Command1_Click()
Dim myDate1 As Date
myDate1 = "01-05-07 01:11:11 pm"
Dim myDate2 As Date
myDate2 = "05-05-07 05:50:55 pm"
MsgBox DateDiff("d", myDate1, myDate2)
MsgBox DateDiff("h", myDate1, myDate2)
MsgBox DateDiff("N", myDate1, myDate2)
MsgBox DateDiff("S", myDate1, myDate2)
End Sub
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
May 2nd, 2007, 10:31 AM
#5
Thread Starter
Frenzied Member
Re: Difference between two dates durations
Thanks guys!
But this could not be right.
Code:
Dim myDate1 As Date
myDate1 = "01-05-07 01:11:11 pm"
Dim myDate2 As Date
myDate2 = "05-05-07 05:50:55 pm"
Dim strDifference As String
strDifference = DateDiff("d", myDate1, myDate2) & " days - " & _
DateDiff("h", myDate1, myDate2) & " hours - " & _
DateDiff("n", myDate1, myDate2) & " minutes - " & _
DateDiff("s", myDate1, myDate2) & " seconds."
MsgBox "The difference between mydate2 and mydate1 is: " & strDifference
End
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
May 2nd, 2007, 11:09 AM
#6
Re: Difference between two dates durations
Oh, yes it could be and is..... but it's being misused..... I'm guessing the days part is probably OK.... but I'm betting that you took one look at the hours minutes and seconds and went WOAH!.... but it's right..... For instance, if you look at the datediff between "5/2/2007" and "5/3/2007" using days... you get 1. If you use the same dates, but look at hours.... you get 24... both are correct. If you look at minutes you get (24*60).... all of which are correct.... Now, if you want 5 days, 3 hours, 27 minutes and 6 seconds..... it gets a little more complicated.
First get the number of days.... then get the number of total hours, then subtract from that (days * 24) ..... what's left will get you the hours.... and so on and so on down through seconds. Like I said it gets complicated realy fast.
-tg
-
May 2nd, 2007, 12:48 PM
#7
Re: Difference between two dates durations
you can do it like this
Code:
Const sFormat As String = " \da\y\s hh \hour\s mm \mi\nute\s ss \se\co\n\d\s"
Dim d1 As Date, d2 As Date
d1 = #5/1/2007 1:11:11 PM#
d2 = #5/5/2007 5:50:55 PM#
Debug.Print Int(d2 - d1) & Format$(d2 - d1, sFormat)
Last edited by bushmobile; May 2nd, 2007 at 12:53 PM.
Reason: matched example to poster's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|