I'm trying to subtract a certain amount of seconds from a date for usage elsewhere. However, I need it to be 24hr format. Here is the function I have:
Function getDateTime(df) 'timediff
getDateTime = DateAdd("S",0 - df,Now)
End Function
It needs to be in the format of 10/5/2015 13:58:32
instead of 10/5/2015 1:58:32 PM
Is there an easy way to convert this or do I need to do string evaluation and manipulation? (if hrs > 12 { etc... })
Dealt with this in a another question.
VBScript Date/Time is stored as an integer when you see a particular format that is just the runtime inferring a default string representation of that Date/Time variable (usually using the computers regional settings).
Function FormatDate(df)
FormatDate = Right("00" & Day(df), 2) & _
"/" & Right("00" & Month(df), 2) & "/" & Year(df) & _
" " & Right("00" & Hour(df), 2) & ":" & _
Right("00" & Minute(df), 2) & ":" & Right("00" & Second(df), 2)
End Function
There is other things you could do that use Left(MonthName(Month(df)), 3)
to avoid issues with date format when you have dates like 04/04/2015
for example (as long as the DBMS supports it).