' CerebroJD's Solution to VBScript's Time Format Shortfalls
' =========================================================
' 1 = 24-hour time HH:mm
' 2 = 12-hour time hh:mm
' 3 = 12-hour time hh:mm (With leading zero)
' 4 = 12-hour time hh:mm TT
' 5 = 12-hour time hh:mm TT (With leading zero)
Function BuildTime(mode)
If mode = 1 Then
BuildTime = FormatDateTime(Now(), 4)
ElseIf mode = 2 Then
Hours = Left(FormatDateTime(Now(), 4), 2)
If Hours > 12 Then
Hours = Hours - 12
End If
BuildTime = Hours & Mid(FormatDateTime(Now(), 4), 3, 3)
ElseIf mode = 3 Then
Hours = Left(FormatDateTime(Now(), 4), 2)
If Hours > 12 Then
Hours = Hours - 12
End If
If Hours < 10 Then
Hours = "0"&Hours
End If
BuildTime = Hours & Mid(FormatDateTime(Now(), 4), 3, 3)
ElseIf mode = 4 Then
isMorning = "AM"
Hours = Left(FormatDateTime(Now(), 4), 2)
If Hours > 12 Then
Hours = Hours - 12
isMorning = "PM"
End If
BuildTime = Hours & Mid(FormatDateTime(Now(), 4), 3, 3) & " " & isMorning
ElseIf mode = 5 Then
isMorning = "AM"
Hours = Left(FormatDateTime(Now(), 4), 2)
If Hours > 12 Then
Hours = Hours - 12
isMorning = "PM"
End If
If Hours < 10 Then
Hours = "0"&Hours
End If
BuildTime = Hours & Mid(FormatDateTime(Now(), 4), 3, 3) & " " & isMorning
End If
End Function