MongoDB $dateToString Format Specifiers

The following table outlines the format specifiers that can be used with the $dateToString aggregation pipeline operator in MongoDB.

SpecifierDescriptionPossible Values
%dDay of Month (2 digits, zero padded)01–31
%GYear in ISO 8601 format 0000–9999
%HHour (2 digits, zero padded, 24-hour clock)00–23
%jDay of year (3 digits, zero padded)001–366
%LMillisecond (3 digits, zero padded)000–999
%mMonth (2 digits, zero padded)01–12
%MMinute (2 digits, zero padded)00–59
%SSecond (2 digits, zero padded)00–60
%wDay of week (1-Sunday, 7-Saturday)1–7
%uDay of week number in ISO 8601 format (1-Monday, 7-Sunday)1–7
%UWeek of year (2 digits, zero padded)00–53
%VWeek of Year in ISO 8601 format01–53
%YYear (4 digits, zero padded)0000–9999
%zThe timezone offset from UTC.+/-[hh][mm]
%ZThe minutes offset from UTC as a number. For example, if the timezone offset (+/-[hhmm]) was +0445, the minutes offset is +285.+/-mmm
%%Percent Character as a Literal%

The above table is based on the table from the MongoDB documentation for the $dateToString operator.