Skip to main content
DuckDB’s temporal scalar functions as free functions in better_duck_diesel::dsl::*.
These need the chrono feature for the Rust-side mapping of Date/Time/Timestamp values (or core’s native date_native structs without it). chrono is not on by default in this crate — enable it first.

Extracting parts

Timestamp -> BigInt unless noted: year, month, day, hour, minute, second, epoch(ts) (→Double, seconds since the Unix epoch), date_trunc(part: Text, ts) (→Timestamp, truncate to 'day'/'month'/'hour'/…), strftime(ts, format: Text) (→Text, format a timestamp).

Calendar parts and differences

Timestamp -> BigInt unless noted: dayofweek(ts), isodow(ts), dayofyear(ts), weekofyear(ts), quarter(ts), dayname(ts) (→Text), monthname(ts) (→Text), last_day(d: Date) (→Date), datediff(part: Text, start, finish) (→BigInt, whole part units between two timestamps).

Building dates, times, and timestamps

make_timestamp takes microseconds since the Unix epoch, matching DuckDB’s native TIMESTAMP resolution.

See also

Type mapping

DATE / TIME / TIMESTAMP / TIMESTAMPTZ ↔ chrono.

Numeric & utility

Math on the BigInt/Double results.

Feature flags

chrono vs the native date path.

DSL overview

The rest of the DSL.