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
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Native | 8.0 | |
| PostgreSQL | Native | 9.4 | |
| SQL Server | Native | 2016 | |
| Oracle | Native | 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: Native since 8.0
PostgreSQL: Native since 9.4
SQL Server: Native since 2016
Oracle: Native since 12c
SQLite: Not supported
Per-Database Syntax & Notes
MySQL Native syntax
SELECT STR_TO_DATE('2023-10-01', '%Y-%m-%d');
PostgreSQL Native syntax
SELECT TO_DATE('2023-10-01', 'YYYY-MM-DD');
SQL Server Native syntax
SELECT CONVERT(DATETIME, '2023-10-01', 120);
Oracle Native syntax
SELECT TO_DATE('2023-10-01', 'YYYY-MM-DD') FROM DUAL;