What is the syntax to format a date?

FormatDateTime(date, format)
‘date is a mandatory parameter
‘format is values 0-4 each representing a certain format; optional parameter

Possible values for format parameter:

  • 0 = vbGeneralDate – Default
  • 1 = vbLongDate – Returns date
  • 2 = vbShortDate – Returns date
  • 3 = vbLongTime – Returns time
  • 4 = vbShortTime – Returns time

‘examples
MsgBox (FormatDateTime("2064-08-15 20:25")) ‘returns 8/15/2064 8:25:00PM
MsgBox (FormatDateTime(#5/21/2075#, 1)) ‘Tuesday, May 21, 2075
MsgBox (FormatDateTime(#5/21/2075#, 2)) ‘5/21/2075
MsgBox (FormatDateTime("12:34:17", 3)) ‘12:34:17 PM
MsgBox (FormatDateTime("2050-08-21 12:34:17", 4)) ‘returns 12:34
Advertisements