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. Returnsnull if input is invalid. Returns the original date if unit is unrecognized.
Examples
Example 1: Truncate to Day
Example 2: Truncate to Month
Example 3: Group Events by Week
Example 4: Monthly Aggregation
Example 5: Quarter Analysis
Notes
- Returns
nullfor 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
- date.format - Format date to string
- date.parse - Parse string to date
- date.toTimeZone - Convert date to timezone
Frequently Asked Questions
What does flex.date.truncate do?
What does flex.date.truncate do?
It truncates a date/time value to a specific unit (e.g., day, month, year), zeroing out all smaller components.
What units can I truncate to?
What units can I truncate to?
You can truncate to units such as
year, month, day, hour, minute, and second.