Scalar Functions — DateTime
KQL has a rich set of datetime functions for bucketing, truncating, formatting, and converting timestamps. Most functions work across all five dialects. The remaining gaps are approximations where a dialect lacks a native interval/timespan type — notably totimespan() in SQLite and MySQL, and datetime_add() with non-literal amounts in SQLite.
Legend: ✅ Supported · ⚠️ Approximated · ❌ Not Supported · 🔄 Rewritten
| Function | SQLite | MySQL | ClickHouse | PostgreSQL | DuckDB | Notes |
|---|---|---|---|---|---|---|
now() | ✅ | ✅ | ✅ | ✅ | ✅ | SQLite: datetime('now') |
ago(duration) | ✅ | ✅ | ✅ | ✅ | ✅ | All units supported; sub-second normalized to seconds |
datetime(val) | ✅ | ✅ | ✅ | ✅ | ✅ | CAST to timestamp; MySQL: DATETIME |
todatetime() | ✅ | ✅ | ✅ | ✅ | ✅ | CAST to timestamp; MySQL: DATETIME |
make_datetime() | ✅ | ✅ | ✅ | ✅ | ✅ | SQLite: built via printf+datetime; Postgres/DuckDB: make_timestamp |
datetime_diff() | ⚠️ | ✅ | ✅ | ✅ | ✅ | SQLite: julianday/strftime math — year/month are exact, but other units (notably week) are approximated unreliably and an unrecognized unit silently returns a day count, with no warning; DuckDB: datediff |
datetime_add() | ⚠️ | ✅ | ✅ | ✅ | ✅ | SQLite: literal amounts only; DuckDB: + INTERVAL |
datetime_part() | ⚠️ | ✅ | ✅ | ✅ | ✅ | SQLite: strftime — only the common parts map; quarter, week_of_year, dayofyear, and sub-second parts are unsupported; Postgres/MySQL/DuckDB: EXTRACT; ClickHouse: fixed part set |
format_datetime() | ✅ | ✅ | ✅ | ✅ | ✅ | Format tokens translated per dialect; DuckDB: strftime |
startofday() | ✅ | ✅ | ✅ | ✅ | ✅ | Postgres/DuckDB: date_trunc |
startofmonth() | ✅ | ✅ | ✅ | ✅ | ✅ | |
startofweek() | ✅ | ✅ | ✅ | ✅ | ✅ | |
startofyear() | ✅ | ✅ | ✅ | ✅ | ✅ | |
endofday() | ✅ | ✅ | ✅ | ✅ | ✅ | DuckDB matches Postgres (date_trunc + interval − 1µs) |
endofmonth() | ✅ | ✅ | ✅ | ✅ | ✅ | SQLite: datetime modifier chain; Postgres/DuckDB: date_trunc + interval |
endofweek() | ✅ | ✅ | ✅ | ✅ | ✅ | Sunday-based; Postgres/DuckDB shift date_trunc('week') back one day |
endofyear() |