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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/Time Calculations (Possibly DateDiff)

Status
Not open for further replies.

abhodges

Technical User
Aug 27, 2002
6
0
0
US
I am trying (without much luck) to calculate the elapsed time in days and hours between two date fields. Anyone care to help?

Oh ya, I know almost nothing about VBScipt!

Brusifer
 
DateDiff(h, date1, date2) should do the trick The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Sorry, should have also stated that I am working with long date formats, including time. eg. Wednesday August 28, 2002 6:14pm. DateDiff doesn't seem to work when the time is included.
 
DateDiff should work with long dates... Try using IsDate to verify that the date is being passed correctly.

Code:
If Not IsDate(dtNow) Then
  MsgBox "dtNow: " & dtNow & " is not a valid date."
End If

If Not IsDate(dtThen) Then
  MsgBox "dtThen: " & dtThen & " is not a valid date."
End If

lElapsed = DateDiff(h, dtThen, dtNow)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top