influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

feat: Implement `date_part` scalar function

Open devanbenz opened this issue 4 weeks ago • 0 comments

Implement date_part(part, expression)

Arguments

- part: Part of the date to return. The following date parts are supported:
   - year
    - quarter (emits value in inclusive range [1, 4] based on which quartile of the year the date is in)
    - month
    - week (week of the year)
    - day (day of the month)
    - hour
    - minute
    - second
    - millisecond
    - microsecond
    - nanosecond
    - dow (day of the week where Sunday is 0)
    - doy (day of the year)
    - epoch (seconds since Unix epoch)
    - isodow (day of the week where Monday is 0)
- expression: Time expression to operate on. Must be time VarRef

Example usage:

SELECT * FROM some_measurement
WHERE time >= now() - 10d AND time <= now() AND (date_part(time, dow) != 0 AND date_part(time, dow) != 6)
SELECT value, date_part('hour', time) FROM some_measurement

Please see https://github.com/influxdata/influxdb/issues/27001#issuecomment-3628596053 for additional information on date_part limitations in 1.x.

devanbenz avatar Dec 03 '25 20:12 devanbenz