In Oracle, the TO_DATE function converts a string value to DATE data type value using the specified format.
In MySQL, you can use STR_TO_DATE function. Note that the TO_DATE and STR_TO_DATE format strings are different.
Oracle:
-- Specify a datetime string literal and its exact format SELECT TO_DATE('2013-02-11', 'YYYY-MM-DD') FROM dual;
MySQL:
-- Specify a datetime string literal and its exact format SELECT STR_TO_DATE('2013-02-11', '%Y-%m-%d');
When you convert Oracle TO_DATE function to STR_TO_DATE function in MySQL, you have to map the format specifiers:
Typical conversion examples:
| Oracle | MySQL | |
| 1 | TO_DATE('2013-02-11', 'YYYY-MM-DD') | STR_TO_DATE('2013-02-11', '%Y-%m-%d) |
| 2 | TO_DATE('11/02/13', 'DD/MM/RR') | STR_TO_DATE('11/02/13','%d/%m/%y') |
| 3 | TO_DATE('20140924', 'YYYYMMDD') STR_TO_DATE('20140924', '%Y%m%d') |
In Oracle TO_DATE, the SSSSS format specifies the number of seconds past midnight:
Oracle:
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'; -- Convert 110 seconds to 1 minute and 50 seconds SELECT TO_DATE('110', 'SSSSS') FROM dual; /* 2025-12-01 00:01:50 */ SELECT TO_DATE('2025-12-24 110', 'YYYY-MM-DD SSSSS') FROM dual; /* 2025-12-24 00:01:50 */
Note that if the date part is not specified it is set to the first day of the current month.
In MySQL, you can use the SEC_TO_TIME function to convert seconds to TIME:
MySQL:
-- Seconds as string (microseconds as added) SELECT SEC_TO_TIME('110'); /* 00:01:50.000000 */ -- Seconds as integer SELECT SEC_TO_TIME(110); /* 00:01:50 */ -- Get the same result as Oracle TO_DATE including the date part (the first day of the current month) SELECT CAST(CONCAT(SUBSTR(NOW(), 1, 8), '01 ', SEC_TO_TIME(110)) AS DATETIME); /* 2025-12-01 00:01:50 */
There are some TO_DATE use cases that may look odd at first, but they can still have meaning:
Oracle:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR'; -- SYSDATE is already DATE, why TO_DATE is used? SELECT TO_DATE(SYSDATE, 'DD/MM/YYYY') FROM dual; -- SYSDATE has the time part, but after TO_DATE it became zero (!) SELECT TO_CHAR(SYSDATE, 'HH24:MI:SS'), TO_CHAR(TO_DATE(SYSDATE, 'DD/MM/YYYY'), 'HH24:MI:SS') FROM dual; /* 23:23:48 00:00:00 */
Note that in TO_DATE(SYSDATE, format) expression Oracle firstly converts SYSDATE to string (!) using NLS_DATE_FORMAT and then converts the string back to DATE using the TO_DATE format.
Important note: Oracle can still convert a string to a date successfully, even if the format specified in TO_DATE does not match, as long as the string matches NLS_DATE_FORMAT or some other supported formats:
Oracle:
-- Format does not match, but Oracle still can convert successfully (!) SELECT TO_DATE('14-SEP-2025', 'DD/MM/YYYY') FROM dual; /* 14-SEP-25 */ -- Does not match, but also recognized SELECT TO_DATE('14.SEP.2025', 'DD/MM/YYYY') FROM dual; /* 14-SEP-25 */
Note that STR_TO_DATE(NOW(), format) returns NULL in MySQL if the format does not match '%Y-%m-%d':
MySQL:
SELECT STR_TO_DATE(NOW(), '%d/%m/%Y'); /* NULL */ /* 1 warning */ SHOW WARNINGS; /* Warning | 1411 | Incorrect datetime value: '2025-09-16 19:52:34' for function str_to_date */ SELECT STR_TO_DATE(NOW(), '%Y-%m-%d'); /* 2025-09-16 */
For more information, see Oracle to MySQL Migration.