SQL - Date & Time

Overview

Manipulate dates and times: current timestamp, add/subtract intervals, extract parts, formatting.

SELECT NOW() AS now, DATE_ADD(CURDATE(), INTERVAL 7 DAY) AS next_week;
SELECT SYSDATETIME() AS now, DATEADD(DAY, 7, CAST(GETDATE() AS date)) AS next_week;
SELECT datetime('now') AS now, date('now','+7 day') AS next_week;

Prerequisite

Load the Standard Test Data.

Live Examples (SQLite)

nownext_week
2025-09-17 20:53:452025-09-24

Extract year/month/day

yearmonthday
20240501

Employees hired in 2021

idfirst_namehired_at
1Ada2021-01-10 10:00:00
2Bob2021-05-05 09:30:00