oxicottin
Learning by pecking away....
- Local time
- Today, 07:22
- Joined
- Jun 26, 2007
- Messages
- 851
I'm trying to write a function for military time to get the short date of a date/time based on the time of the day for the shift that was ran.
Im getting incorrect dates / times for my results
- If the Date/time "DelayStart" is from 6am to 11:59pm then use the "DelayStart" given
- If the Date/time "DelayStart" is from Midnight to 2:59am then use "DelayStart" - 1 to give previous date.
- If the Date/time "DelayStart" is from 3am to 5:59 am then use the "DelayStart" given.
Code:
Public Function getDate(DelayStart as variant)
Dim h as integer: h = DatePart("h", DelayStart)
Dim m as integer: m = DatePart("n", DelayStart)
'12am to 2:29pm use previous DelayStart date
If h >= 0 And h< 2 And IIf(h = 2, IIf(m <= 59, True,False), True) Then
getDate = Format(DelayStart, "Short Date") - 1
'6am to 11:59pm use DelayStart date
ElseIf h >= 6 And h< 23 And IIf(h = 23, IIf(m <= 59, True,False), True) Then
getDate = Format(DelayStart, "Short Date")
Else
getDate = Format(DelayStart, "Short Date")
End if
End Function
Im getting incorrect dates / times for my results
Last edited: