Calendar Date Truncator
Truncate any date to year, quarter, month, week, day, hour, or minute. Get ISO 8601, Unix timestamp, and human-readable output instantly.
About
Date truncation is the operation of zeroing all temporal components below a chosen granularity level. Truncating t to the month level sets the day to 1 and the time to 00:00:00.000. This is not rounding. Rounding considers the midpoint. Truncation always floors toward the start of the period. Confusing truncation with rounding when aggregating time-series data produces off-by-one-period errors in financial reports, billing cycles, and cohort analyses. This tool applies deterministic truncation across seven granularity levels and outputs in four formats simultaneously.
Week truncation follows ISO 8601: weeks start on Monday, and the first week of the year contains the year's first Thursday. Quarter boundaries fall on months 1, 4, 7, and 10. All calculations execute in the browser using native Date arithmetic with no timezone conversion. The input is interpreted as local time. Limitation: dates before the Unix epoch (1970-01-01) produce negative Unix timestamps, which are valid but may confuse downstream systems that expect unsigned integers.
Formulas
The truncation function trunc maps an input datetime t and granularity level g to a new datetime where all components below g are set to their minimum values.
For quarter truncation, the quarter-start month mq is computed as:
where m is the 1-indexed month (1 - 12).
For ISO week truncation, the day-of-week offset δ from Monday is:
where djs is JavaScript's getDay() value (0 = Sunday). The truncated date is then t − δ days, with time zeroed.
The Unix timestamp in seconds:
where tms is milliseconds since epoch from Date.getTime().
Variable legend: t = input datetime, g = granularity level, m = month (1-indexed), mq = quarter-start month, δ = weekday offset from Monday, djs = JavaScript day index, ts = Unix timestamp in seconds, tms = epoch milliseconds.
Reference Data
| Granularity | Zeroed Components | Example Input | Truncated Output | Common Use Case |
|---|---|---|---|---|
| Year | Month, Day, Hour, Min, Sec, Ms | 2024-07-15 14:32:09 | 2024-01-01 00:00:00 | Annual reports |
| Quarter | Month (within Q), Day, Hour, Min, Sec, Ms | 2024-08-22 09:15:00 | 2024-07-01 00:00:00 | Fiscal quarter aggregation |
| Month | Day, Hour, Min, Sec, Ms | 2024-03-17 22:45:30 | 2024-03-01 00:00:00 | Monthly billing cycles |
| ISO Week | Day (to Monday), Hour, Min, Sec, Ms | 2024-01-04 11:00:00 | 2024-01-01 00:00:00 | Sprint planning |
| Day | Hour, Min, Sec, Ms | 2024-12-25 18:30:00 | 2024-12-25 00:00:00 | Daily log partitioning |
| Hour | Min, Sec, Ms | 2024-06-01 14:47:22 | 2024-06-01 14:00:00 | Hourly metrics buckets |
| Minute | Sec, Ms | 2024-09-10 08:33:55 | 2024-09-10 08:33:00 | Cron job alignment |
| Second | Ms | 2024-02-29 12:00:00.789 | 2024-02-29 12:00:00.000 | Log deduplication |
| Quarter Boundary Reference | ||||
| Q1 | January 1 - March 31 | |||
| Q2 | April 1 - June 30 | |||
| Q3 | July 1 - September 30 | |||
| Q4 | October 1 - December 31 | |||
| ISO Week Rules | ||||
| Week Start | Monday | |||
| Week 1 | Contains the year's first Thursday | |||
| Max Weeks | 52 or 53 (long years) | |||
| Unix Timestamp Reference Points | ||||
| Epoch | 1970-01-01T00:00:00Z = 0 | |||
| Y2K | 2000-01-01T00:00:00Z = 946684800 | |||
| Max 32-bit | 2038-01-19T03:14:07Z = 2147483647 | |||