Date & Time Functions
SQL · Methods reference
SQL · Methods reference
📋 Overview
Extract, truncate, and format dates/times.
🔧 Methods
Common
| Function | Description |
|---|---|
NOW() / CURRENT_TIMESTAMP | Current transaction timestamp |
CURRENT_DATE / CURRENT_TIME | Date or time component |
EXTRACT(field FROM ts) | Year, month, day, hour, … |
DATE_TRUNC(unit, ts) (PG) | Truncate to unit bucket |
AGE(ts1, ts2) (PG) | Interval between timestamps |
DATE_FORMAT(ts, fmt) (MySQL) | Format as string |
TO_CHAR(ts, fmt) (PG) | Format timestamp to string |
TO_DATE(str, fmt) / TO_TIMESTAMP | Parse string to date/time |
INTERVAL '1 day' (PG) | Interval literals |
AT TIME ZONE (PG) | Convert timezone |
💡 Examples
See parent topic notes for runnable snippets; this page is the complete method index.
⚠️ Pitfalls
- Mutating methods return
Nonein Python — do not chainsort()/reverse()expecting a new list. - Default JS
sort()compares strings — pass(a,b) => a-bfor numbers. - SQL function names differ by dialect — verify Postgres vs MySQL docs.
- Django
QuerySet.update()skipssave()signals and autoauto_nowfields on models.