Customizable Date Formatting Routine

This demo illustrates Ken Schaefer's customizable date formatting string. You can specify a date and format string and the function will return a string with the format specified. The valid formatting features include:

Formatting Identifiers
%mMonth as a decimal (02)
%BFull month name (February)
%bAbbreviated month name (Feb )
%dDay of the month (23)
%OOrdinal of day of month (eg st or rd or nd)
%jDay of the year (54)
%YYear with century (1998)
%yYear without century (98)
%WWeekday as integer (0 is Sunday)
%aAbbreviated day name (Fri)
%AWeekday Name (Friday)
%HHour in 24 hour format (24)
%hHour in 12 hour format (12)
%NMinute as an integer (01)
%nMinute as optional if minute <> 0
%SSecond as an integer (55)
%PAM/PM Indicator (PM)

For example, if we call this function with the code:

Response.Write "Today is " & fncFmtDate(Now(), "%A the %d%O of %B, %Y")

We'll get the following output:
Today is Friday the 22nd of September, 2017

Give it a try yourself! Into the two text boxes below enter the date and the customizable date formatting string.

Date:
Format String:

The output of: fncFmtDate("9/22/2017 10:04:59 AM", %m-%d-%y) is:
9-22-17


[Return to the Article/Code]