SQL Date/Time Functions Reference

Date and time functions across SQL dialects — MySQL, PostgreSQL, SQLite, MSSQL.

Cross-dialect SQL date/time function reference covering NOW, DATEADD, EXTRACT, DATE_TRUNC and format functions, with side-by-side syntax for MySQL, PostgreSQL, SQLite and SQL Server.

Why do DATEADD and DATE_ADD differ?

They are different vendor implementations of the same idea. SQL Server uses DATEADD(unit, n, date), MySQL uses DATE_ADD(date, INTERVAL n unit) and PostgreSQL uses plain interval arithmetic like date + INTERVAL '7 days'. The SQL standard never settled one spelling.

One concept, four spellings

Date and time handling is where SQL portability breaks down fastest. Every major engine has its own function names, argument order and timezone defaults for the same logical operations. This reference puts the common tasks — current time, adding intervals, extracting fields, truncating and formatting — side by side across MySQL, PostgreSQL, SQLite and SQL Server so you can translate at a glance.

How it works

Each task maps to one expression per dialect. The differences fall into a few predictable buckets:

-- Add seven days
DATE_ADD(d, INTERVAL 7 DAY)   -- MySQL
d + INTERVAL '7 days'         -- PostgreSQL
date(d, '+7 days')            -- SQLite
DATEADD(DAY, 7, d)            -- SQL Server

Watch three things: argument order (SQL Server puts the unit first), the interval syntax (a keyword in MySQL, a string in Postgres), and whether the result is a date, datetime or text value. Functions like strftime in SQLite always return text, so wrap them in CAST(... AS INTEGER) when you need a number.

Conventions that bite

Day-of-week numbering is the classic trap: Sunday is 1 in MySQL, 0 in PostgreSQL and SQLite, and configurable in SQL Server via SET DATEFIRST. Unix-epoch extraction also overflows a 32-bit INT past the year 2038 in SQL Server’s DATEDIFF(SECOND, ...), so use DATEDIFF_BIG there. When in doubt, confirm timezone defaults — NOW() is local in some engines and UTC in others.