Skip to main content

Description

Truncates a date/time value to the specified unit (e.g., day, month, year), setting all smaller units to their minimum values. All operations are UTC-based.

Syntax

Parameters

Supported Units

Returns

Type: Date A new Date object truncated to the specified unit. Returns null if input is invalid. Returns the original date if unit is unrecognized.

Examples

Example 1: Truncate to Day

Output:

Example 2: Truncate to Month

Output:

Example 3: Group Events by Week

Example 4: Monthly Aggregation

Example 5: Quarter Analysis

Notes

  • Returns null for invalid date inputs
  • All operations use UTC timezone
  • Week starts on Monday (ISO week convention)
  • Quarters: Q1 (Jan-Mar), Q2 (Apr-Jun), Q3 (Jul-Sep), Q4 (Oct-Dec)
  • Unknown units return the original normalized date
  • Useful for time-series aggregation and bucketing

See Also

Frequently Asked Questions

It truncates a date/time value to a specific unit (e.g., day, month, year), zeroing out all smaller components.
You can truncate to units such as year, month, day, hour, minute, and second.