Timestamps and durations#
CEL handles timestamps and durations natively. Extract components, measure elapsed time, and enforce time-based rules. Examples on this page use this message:
{
"name": "Alice",
"roles": ["admin", "editor", "viewer"],
"age": 30,
"email": "alice@example.com",
"created": timestamp("2025-12-14T00:00:00Z"),
"email_verified": timestamp("2025-12-14T18:30:00Z")
}
Extracting components#
getFullYear(), getMonth(), getDayOfMonth(), and getHours() extract individual parts of a timestamp.
Months are zero-indexed: January is 0, December is 11.
Duration comparisons#
Subtract two timestamps to get a duration, then compare.
Did the user verify their email within 24 hours of signing up?
A stricter check (within 1 hour) fails.
Timestamp arithmetic#
Add a duration to a timestamp to compute a future date.
CEL durations support hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.
There is no day or month unit.
Use "720h" for 30 days and "8760h" for 365 days.
Time-based rules#
Check whether a timestamp falls in a specific year.
Check whether verification happened during business hours (9 AM to 5 PM UTC).
The user verified at 18:30 UTC, outside the 9-17 window.
See also#
- Time - Timestamp construction, timezone handling, duration components, and numeric conversions
- Arithmetic operators - Numeric arithmetic and operator precedence
- At a glance - Every function, macro, and operator