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)
| now | next_week |
|---|---|
| 2025-11-28 19:05:03 | 2025-12-05 |
Extract year/month/day
| year | month | day |
|---|---|---|
| 2024 | 05 | 01 |
Employees hired in 2021
| id | first_name | hired_at |
|---|---|---|
| 1 | Ada | 2021-01-10 10:00:00 |
| 2 | Bob | 2021-05-05 09:30:00 |