TO_DATE
This function is available from MariaDB 12.3.
Syntax
TO_DATE(string_expression [DEFAULT string_expression ON CONVERSION ERROR],
format_string [,NLS_FORMAT_STRING])Description
TO_DATE was added for Oracle support.
The allowed separators are the same as for
TO_CHAR(): space (), tab (\t), and any of!,#,%,',(,),*,+,-,.,/,:,;,<,=, or>.&can be used if the next character is not a character in thea-zorA-Zrange.textindicates a text string that is used verbatim in the format. You cannot use the double-quote (") as a separator.NLS_FORMAT_STRINGsupports these options:NLS_CALENDAR=GREGORIANandNLS_DATE_LANGUAGE=language, wherelanguagecan be one of the following:All MariaDB short locales, like
en_AU.The following Oracle language names: ALBANIAN, AMERICAN, ARABIC, BASQUE, BELARUSIAN, BRAZILIAN PORTUGUESE, BULGARIAN, CANADIAN FRENCH, CATALAN, CROATIAN, CYRILLIC SERBIAN, CZECH, DANISH, DUTCH, ENGLISH, ESTONIAN, FINNISH, FRENCH, GERMAN, GREEK, HEBREW, HINDI, HUNGARIAN, ICELANDIC, INDONESIAN, ITALIAN, JAPANESE, KANNADA, KOREAN, LATIN AMERICAN SPANISH, LATVIAN, LITHUANIAN, MACEDONIAN, MALAY, MEXICAN SPANISH, NORWEGIAN, POLISH, PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED CHINESE, SLOVAK, SLOVENIAN, SPANISH, SWAHILI, SWEDISH, TAMIL, THAI, TRADITIONAL CHINESE, TURKISH, UKRAINIAN, VIETNAMESE
Supported Format Elements
AD– Anno Domini ("in the year of the Lord")AD_DOT– Anno Domini ("in the year of the Lord")AM– Meridian indicator (before midday)AM_DOT– Meridian indicator (before midday)DAY– Name of dayDD– Day (1-31)DDD– Day of year (1-336)DY– Abbreviated name of dayFF[1-6]– Fractional secondsHH– Hour (1-12)HH12– Hour (1-12)HH24– Hour (0-23)MI– Minutes (0-59)MM– Month (1-12)MON– Abbreviated name of monthMONTH– Name of MonthPM– Meridian indicator (after midday)PM_DOT– Meridian indicator (after midday)RR– 20th century dates in the 21st century. 2 digits in the50-99range are assumed starting from the year 2000, and0-49is assumed from 1900.RRRR– 20th century dates in the 21st century. 4 digitsSS– SecondsSYYYY– Signed 4-digit year; MariaDB only supports positive yearsY– 1-digit yearYY– 2-digit yearYYY– 3-digit yearYYYY– 4 digit year
If no datetime is given, the current datetime is used. For example, if 'MM-DD HH-MM-SS' is given, the current year is used. (This is Oracle behavior.)
Unsupported Options
BC,D,DL,DS,E,EE,FM,FX,RM,SSSSS,TS,TZD,TZH,TZR,X, andSY BCare not supported by MariaDB datetime.Most other formats do not make sense in a MariaDB context, as we return
datetimewith fractions, not as a string.D(day-of-week) is not supported as it is not clear how it would map to MariaDB. This element depends on the NLS territory of the session.RRonly works with 2-digit years. (In Oracle,RRmay also work with 4-digit years in some context, but the rules are not clear.)
Extensions and Differences Compared to Oracle
MariaDB supports
FF(fractional seconds). IfFF[#]is used,TO_DATEreturns adatetimewith#of subseconds. IfFFis not used, adatetimeis returned. A warning (but no error) is issued if the string contains more digits than specified withF(#].Names can be shortened to their unique prefixes. For example, both
JanuaryandJawork fine.No error is issued if the datetime string is shorter than
format_stringand the next unused character is not a number. This is useful to get adatetimefrom a mixed set of strings indatetimeformat. By contrast, Oracle gives an error if thedatetimestring is too short.MariaDB supports short locales as language names.
NLS_DATE_FORMATcan use double-quote (") and single-quote (') for quoting.NLS_DATE_FORMATmust be a constant string. This is to ensure that the server knows which locale to use when executing the function.
Examples
Convert a textual date and time to DATE format:
Last updated
Was this helpful?

