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

DateAdd on 12 Hour Clock 1

Status
Not open for further replies.

Error7

Programmer
Jul 5, 2002
656
0
16
GB
I'm trying to figure out how to apply a negative DateAdd to a time defined as "01:30:00 AM" while retaining the AM / PM prefix.

So if FileTime = "08:04:45 AM"
NewTime = DateAdd("h", -7, FileTime)
This returns the time in 24 hour format as "23:04:45"


[gray]Experience is something you don't get until just after you need it.[/gray]
 
All times are 24 hour format. The AM/PM stuff is just formatting.
Code:
FileTime = "08:04:45 AM" 
NewTime = DateAdd("h", -7, FileTime) 
Debug.Print Format(NewTime,"hh:nn:ss AMPM")

Produces: 01:04:45 AM

Note that seven hours before 08:04:45 AM is 01:04:45 AM and not 11:04:45 PM as your example indicates.
 
"Note that seven hours before 08:04:45 AM is 01:04:45 AM and not 11:04:45 PM as your example indicates. "

Quite right Golam, I was rushing to post my question before leaving the office.

Thanks for the format tip.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top