Functions for parsing strings into dates.

Converting string representations of dates into actual date/time types using format masks. Essential for importing text data from external sources. Use TRY_TO_DATE where available to handle invalid dates gracefully instead of failing.

Compatibility

Show:
Database System Support Status Since Version Notes
MySQL ✓ Supported 8.0
PostgreSQL ✓ Supported 9.4
SQL Server ✓ Supported 2016
Oracle ✓ Supported 12c
SQLite ✗ Not Supported SQLite does not have a direct function for this.

Details

These functions are crucial for data migration and compatibility across different SQL databases.

Standard Syntax

SELECT STR_TO_DATE('2023-10-01', '%Y-%m-%d');

Version Support

MySQL: Since 8.0 PostgreSQL: Since 9.4 SQL Server: Since 2016 Oracle: Since 12c SQLite: Not supported

Per-Database Syntax & Notes

MySQL

SELECT STR_TO_DATE('2023-10-01', '%Y-%m-%d');

PostgreSQL

SELECT TO_DATE('2023-10-01', 'YYYY-MM-DD');

SQL Server

SELECT CONVERT(DATETIME, '2023-10-01', 120);

Oracle

SELECT TO_DATE('2023-10-01', 'YYYY-MM-DD') FROM DUAL;