mysql / mariadb: NO native DATE_TRUNC exists (verified) — built via
DATE_FORMAT/string-concat + STR_TO_DATE workarounds.
mssql: uses DATETRUNC(datepart, expr), added in SQL Server 2022. For
older MSSQL versions there is no native equivalent; this targets modern
SQL Server.
oracle: TRUNC(expr, fmt). Oracle's TRUNC only truncates down to
hour/minute ('HH24'/'MI'); truncating to 'second' is a no-op since DATE
values already carry second precision, so expr is returned unchanged.
sqlite: no native function — built via strftime()/string-concat.
db2: no native DATE_TRUNC — built via VARCHAR_FORMAT/TIMESTAMP_FORMAT
round-tripping (Db2's TO_CHAR/TO_DATE equivalents) plus DAYOFWEEK()
for week truncation.
snowflake: native DATE_TRUNC('unit', expr).
clickhouse: dedicated toStartOfYear/toStartOfQuarter/toStartOfMonth/
toStartOfWeek/toStartOfDay/toStartOfHour/toStartOfMinute/
toStartOfSecond functions (genuinely different function-per-unit API,
not a single parameterized function).
Truncate a date/timestamp expression down to the start of the given unit boundary (year/quarter/month/week/day/hour/minute/second).
Dialect notes:
DATE_TRUNC('unit', expr).DATE_FORMAT/string-concat +STR_TO_DATEworkarounds.DATETRUNC(datepart, expr), added in SQL Server 2022. For older MSSQL versions there is no native equivalent; this targets modern SQL Server.TRUNC(expr, fmt). Oracle's TRUNC only truncates down to hour/minute ('HH24'/'MI'); truncating to 'second' is a no-op since DATE values already carry second precision, soexpris returned unchanged.strftime()/string-concat.VARCHAR_FORMAT/TIMESTAMP_FORMATround-tripping (Db2's TO_CHAR/TO_DATE equivalents) plusDAYOFWEEK()for week truncation.DATE_TRUNC('unit', expr).toStartOfYear/toStartOfQuarter/toStartOfMonth/toStartOfWeek/toStartOfDay/toStartOfHour/toStartOfMinute/toStartOfSecondfunctions (genuinely different function-per-unit API, not a single parameterized function).