// dates & times reference

SQL PARSE function

Returns a typed value parsed by .NET culture rules, so it also reads month names in other languages, which CONVERT style numbers cannot.

Catégorie
Dates & times
Returns
date / datetime2 (requested type)
In this category
32 of 121

Syntaxe

PARSE('15/01/2024' AS date USING 'en-GB')
TRY_PARSE('...' AS date USING 'en-GB')

Each block is a separate form. The support table and the examples show which engine takes which.

Prise en charge des moteurs

MoteurSupportNotes
SQL Server Oui Supported under this name.
PostgreSQL Different name or syntax to_date / to_timestamp masks
MySQL Different name or syntax STR_TO_DATE masks
SQLite Not built in no culture parsing
Oracle Different name or syntax TO_DATE with an explicit mask

Exemples

SQL Server

SELECT PARSE('15/01/2024' AS date USING 'en-GB') AS parsed;  -- 2024-01-15

SQL Server

SELECT TRY_PARSE('2024-13-40' AS date USING 'en-US') AS parsed;  -- NULL

Bon à savoir

  • PARSE runs through the .NET CLR and is much slower than CAST or CONVERT; keep it for small imports, not bulk loads. It is not remoted to linked servers either.
  • Without USING, PARSE falls back to the session language, so the same string parses differently on two servers.
  • TRY_PARSE swallows the error as NULL, which turns a broken import into silent data loss unless you count the NULLs.

Questions about PARSE / TRY_PARSE

PARSE or CONVERT: which should I use?

CONVERT with a style number for known formats and speed; PARSE only when the input format follows a culture you cannot control.

Why did TRY_PARSE return NULL on good data?

The culture mismatched: 15/01/2024 fails under en-US because there is no month 15. Declare USING 'en-GB' explicitly.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.