FormatDateTime

Formats a date/time in the form of a string in a user-defined format.

Syntax

FormatDateTime(format, dateTime)
format = string specifying the format to use (see below)
dateTime = the date/time that you want to format

Remarks

The format string can contain the following specifiers:

SpecifierDisplay
dDisplays the day number without a zero prefix (from 1 to 31).
ddDisplays the day number with a zero prefix (from 01 to 31).
dddDisplays the abbreviated day (Sun to Sat).
ddddDisplays the whole day (Sunday to Saturday).
mDisplays the month number without a zero prefix (from 1 to 12).
mmDisplays the month number with a zero prefix (from 01 to 12).
mmmDisplays the abbreviated month (Jan to Dec).
mmmmDisplays the whole month (January to December).
yyDisplays the two-digit year number (00 to 99).
yyyyDisplays the four-digit year number (0000-9999).
hDisplays the hour on the 24-hour clock without a zero prefix (0 to 23).
hhDisplays the hour on the 24-hour clock with a zero prefix (00 to 23).
nDisplays the minutes without a zero prefix (0 to 59).
nnDisplays the minutes with a zero prefix (00 to 59).
sDisplays the seconds without a zero prefix (0 to 59).
ssDisplays the seconds with a zero prefix (00 to 59).
zDisplays the milliseconds without a zero prefix (0 to 999).
zzzDisplays the milliseconds with a zero prefix (000 to 999).

Note: when 'mm' or 'm' are preceded by an hour specifier, they are interpreted as 'nn' and 'n' respectively, this allows 'hh:mm' for instance to be accepted as 'hh:nn' would be.

Example

FormatDateTime('yyyy-mm-dd', Now()) = '2010-01-12' on January 12, 2010
FormatDateTime('dddd h:nn', Now()) = 'Friday 9:30' at 9:30 am on October 2, 2009

Classification

DateTime Strings