Skip to main content

Scalar Functions — DateTime

KQL has a rich set of datetime functions for bucketing, truncating, formatting, and converting timestamps. Most functions work across all four dialects. SQLite has the most gaps, particularly for datetime_diff(), datetime_part(), and make_datetime(), which have no equivalent SQLite expression.

Legend: ✅ Supported · ⚠️ Approximated · ❌ Not Supported · 🔄 Rewritten

FunctionSQLiteMySQLClickHousePostgreSQLNotes
now()SQLite: datetime('now')
ago(duration)All units supported; sub-second normalized to seconds
datetime(val)
todatetime()CAST to timestamp
make_datetime()SQLite: unsupported
datetime_diff()SQLite: unsupported
datetime_add()⚠️SQLite: literal values only
datetime_part()SQLite: unsupported
format_datetime()Format tokens translated per dialect
startofday()
startofmonth()
startofweek()
startofyear()
endofday()
endofmonth()SQLite: datetime modifier chain
endofweek()
endofyear()SQLite: datetime modifier chain; MySQL: TIMESTAMP(CONCAT(YEAR(ts),'-12-31 23:59:59')); Postgres: date_trunc + interval; ClickHouse: endOfYear
dayofmonth()
dayofweek()
dayofyear()
hourofday()
monthofyear()
getyear()
weekofyear()
bin(col, interval)⚠️ClickHouse: toStartOfInterval; MySQL: from_unixtime; Postgres: TODO warning
totimespan()⚠️⚠️SQLite/MySQL: approximated as raw seconds with warning
format_timespan()⚠️⚠️ClickHouse: formatReadableTimeDelta; others: CAST to TEXT with warning
unixtime_seconds_todatetime()
unixtime_milliseconds_todatetime()Divides by 1000
unixtime_microseconds_todatetime()Divides by 1,000,000
unixtime_nanoseconds_todatetime()Divides by 1,000,000,000