MariaDB Date Format Strings

Below is a full list of format specifiers that can be used in format strings with functions like DATE_FORMAT(), STR_TO_DATE(), and FROM_UNIXTIME() in MariaDB.

OptionDescription
%aShort weekday name in current locale (Variable lc_time_names).
%bShort form month name in current locale. For example, Feb (when using en_US).
%cMonth with 1 or 2 digits.
%DDay with English suffix th, nd, st or rd. (1st, 2nd, 3rd…).
%dDay with 2 digits.
%eDay with 1 or 2 digits.
%fSub seconds 6 digits.
%HHour with 2 digits between 00-23.
%hHour with 2 digits between 01-12.
%IHour with 2 digits between 01-12.
%iMinute with 2 digits.
%jDay of the year (001-366)
%kHour with 1 digits between 0-23.
%lHour with 1 digits between 1-12.
%MFull month name in current locale (Variable lc_time_names).
%mMonth with 2 digits.
%pAM/PM according to current locale (Variable lc_time_names).
%rTime in 12 hour format, followed by AM/PM. Short for %I:%i:%S %p.
%SSeconds with 2 digits.
%sSeconds with 2 digits.
%TTime in 24 hour format. Short for %H:%i:%S.
%UWeek number (00-53), when first day of the week is Sunday.
%uWeek number (00-53), when first day of the week is Monday.
%VWeek number (01-53), when first day of the week is Sunday. Used with %X.
%vWeek number (01-53), when first day of the week is Monday. Used with %x.
%WFull weekday name in current locale (Variable lc_time_names).
%wDay of the week. 0 = Sunday, 6 = Saturday.
%XYear with 4 digits when first day of the week is Sunday. Used with %V.
%xYear with 4 digits when first day of the week is Monday. Used with %v.
%YYear with 4 digits.
%yYear with 2 digits.
%#For STR_TO_DATE(), skip all numbers.
%.For STR_TO_DATE(), skip all punctation characters.
%@For STR_TO_DATE(),skip all alpha characters.
%%A literal % character.

Example

Here’s an example of using some of the above format specifiers to provide a format string for the DATE_FORMAT() function:

SELECT DATE_FORMAT('2030-01-25 10:30:45', '%r %W, %D %M %Y');

Result:

+-------------------------------------------------------+
| DATE_FORMAT('2030-01-25 10:30:45', '%r %W, %D %M %Y') |
+-------------------------------------------------------+
| 10:30:45 AM Friday, 25th January 2030                 |
+-------------------------------------------------------+

The GET_FORMAT() Function

In addition to the above individual format specifiers, you can use the GET_FORMAT() function to return the full format string, without needing to remember which format specifiers, and in which order, to include in the format string. This function can be useful for when working with functions that require a format string.