Code Reference

Date & Time Functions

SQL · Methods reference

SQL · Methods reference


📋 Overview

Extract, truncate, and format dates/times.

🔧 Methods

Common

FunctionDescription
NOW() / CURRENT_TIMESTAMPCurrent transaction timestamp
CURRENT_DATE / CURRENT_TIMEDate 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_TIMESTAMPParse 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 None in Python — do not chain sort() / reverse() expecting a new list.
  • Default JS sort() compares strings — pass (a,b) => a-b for numbers.
  • SQL function names differ by dialect — verify Postgres vs MySQL docs.
  • Django QuerySet.update() skips save() signals and auto auto_now fields on models.

On this page