Formatting Dates

Scripting Guides

Use the case-sensitive strftime flags below to format dates and times.

Date Flags

%Y      The full year, including century. (1999, 2001)
%C      The year's century, rounding down. (19, 20)
%y      The last two digits of the year. (99, 01)

%m      Month of the year. (01, 12)
  %_m   Blank-padded month of the year. ( 1, 12)
  %-m   Unpadded month of the year. (1, 12)

%B      The full month name. (January, February)
  %^B   Uppercased full month name. (JANUARY, FEBRUARY)
%b      The abbreviated month name. (Jan, Feb)
  %^b   Uppercased abbreviated month name. (JAN, FEB)

%d      Day of the month. (01, 31)
  %_d   Blank-padded day of the month. ( 1, 31)
  %-d   Unpadded day of the month. (1, 31)

%j      Day of the year. (001, 366)
  %_j   Blank-padded day of the year. (  1, 366)
  %-j   Unpadded day of the year. (1, 366)

Time Flags

%H      Hour of the day, 24-hour clock. (00, 23)
  %_H   Blank-padded hour of the day, 24-hour clock. ( 0, 23)
  %-H   Unpadded hour of the day, 24-hour clock. (0, 23)

%I      Hour of the day, 12-hour clock (01, 12)
  %_I   Blank-padded hour of the day, 12-hour clock. ( 1, 12)
  %-I   Unpadded hour of the day, 12-hour clock. (1, 12)

%P      Uppercase meridian indicator. (AM, PM)
%p      Lowercase meridian indicator. (am, pm)

%M      Minute of the hour. (00, 59)
  %_M   Blank-padded minute of the hour. ( 0, 59)
  %-M   Unpadded minute of the hour. (0, 59)

%S      Second of the minute. (00, 59)
  %_S   Blank-padded second of the minute. ( 0, 59)
  %-S   Unpadded second of the minute. (0, 59)

Week Flags

%U      Week number of the year, starting with Sunday. (00, 53)
  %_U   Blank-padded week number of the year, starting with Sunday. ( 0, 53)
  %-U   Unpadded week number of the year, starting with Sunday. (0, 53)

%W      Week number of the year, starting with Monday. (00, 53)
  %_W   Blank-padded week number of the year, starting with Monday. ( 0, 53)
  %-W   Unpadded week number of the year, starting with Monday. (0, 53)

%A      The full weekday name. (Sunday, Monday)
  %^A   Uppercased full weekday name. (SUNDAY, MONDAY)

%a      Abbreviated weekday name. (Sun, Mon)
  %^a   Uppercased abbreviated weekday name. (SUN, MON)