Truncates the date to the specified date part.
See Sigma's Common Date Functions and Use Cases lab for more information about date functions, including use cases and exercises.
DateTrunc(precision, date, [timezone])
precision (required) Smallest date part to preserve, chosen from “year”, "quarter", “month”, “week”, "week_starting_sunday", "week_starting_monday", “day”, “hour”, “minute”, and “second”. If "week" is selected, DateTrunc will have weeks start on Sunday. Parameters may be used to specify precision!
date (required) Date to be truncated.
timezone (optional) Name of IANA time zone to get the date part at, e.g.”America/Los_Angeles”. When calculating a time zone, input dates are treated as UTC.
The output returned is presented in the organization's time zone. This may cause days, months, or years to appear offset if the specified time zone is ahead of the organization time zone. To view the output presented in the specified time zone, you can apply ConvertTimezone to it.
DateTrunc("hour", Date("1980-05-22 8:45:30"))
- Returns 1980-05-22 8:00:00, discarding the “minute” and”second” components of the date.
DateTrunc("day", Date("1980-05-22 8:45:30"))
- Returns 1980-05-22 00:00:00, discarding the time components of the date.