Home > Documentation > Oracle to MySQL

How to convert Oracle built-in functions TO_CHAR and TO_DATE to MySQL

Oracle built-in function TO_DATE($string,$format) must be replaced by STR_TO_DATE($string,$format) and TO_CHAR($date,$format) - by DATE_FORMAT($date,$format) MySQL function with respect to difference for date format specifiers in Oracle and MySQL illustrated by this table:

Oracle MySQL Meaning
DD %d Day (1 - 31)
DY %a Abbreviated day (Sun - Sat)
HH or HH12 %h Hour (1 - 12)
HH24 %H Hour (0 - 23)
MI %i Minutes (0 - 59)
MM %m Month (1 - 12)
MON %b Abbreviated month (Jan - Dec)
MONTH %M Month name (January - December)
RR %y 2-digit year, 20th century for 00-49
RRRR %Y 2 or 4-digit year, 20th century for 00-49
SS %s Seconds (0 - 59)
YY %y 2-digit year
YYYY %Y 4-digit year