DateTrunc

Truncates the date to the specified date part. All parts of the date smaller than the the specified part are truncated to their minimum value.

Usage

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 can 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.

Notes

  • Sigma presents the output in the organization's time zone. This might 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. For more information, see Account time zone.
  • The precision argument does not support columns.

Example

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.
DateTrunc("month", [Order Date])
  • Returns the first day of the month for each date in the Order Date column.