SQL Server: date literals in ODBC canonical format
Write language-independent dates, times and timestamps using the {d}, {t} and {ts} syntax.
The format of a date in SQL code depends on language and regional settings, which causes interpretation issues. The ODBC canonical format gives a notation that does not depend on those settings.
| Type | Syntax | Example |
|---|---|---|
| Date | {d 'yyyy-mm-dd'} |
{d '2001-12-31'} |
| Timestamp | {ts 'yyyy-mm-dd hh:mm:ss'} |
{ts '2001-12-31 00:00:00'} |
| Time | {t 'hh:mm:ss'} |
{t '13:45:00'} |
SELECT * FROM dbo.Orders WHERE OrderDate >= {d '2001-12-31'};
The dbo.Orders table in this example is fictitious.