timestamp columns on your data, such as events.requested_at and users.created_at / users.updated_at. Unless noted otherwise, each entry works on both the PostgreSQL and ClickHouse backends.
timestamp ± INTERVAL
Add or subtract a fixed span of time to or from a timestamp using an interval literal. This is the most portable way to express relative time windows. Syntaxtimestamp— the timestamp (or date) to shift.quantity unit— an interval literal such as'30 days','6 hours', or'1 month'.
- A timestamp shifted forward (for
+) or backward (for-) by the interval.
Events in the last 30 days
now
Returns the current date and time. Syntax- The current timestamp.
Events in the last hour
current_date
Returns the current date, with no time component. Syntax- The current date.
Users created today
date_diff
Counts the number of unit boundaries crossed between a start and an end timestamp. Syntaxunit— the unit to count, one ofday,hour,minute,second,week,month,quarter, oryear.startdate— the earlier timestamp.enddate— the later timestamp.
- The whole number of units between
startdateandenddate.
Days since each user signed up
date_trunc
Truncates a timestamp down to the start of the specified unit. Syntaxunit— the precision to truncate to, one ofday,hour,minute,week,month,quarter, oryear.timestamp— the timestamp to truncate.
- The timestamp truncated to the start of the given unit.
Event counts by month
extract
Extracts a single field, such as the year or day of week, from a timestamp. Syntaxfield— the field to extract, one ofYEAR,MONTH,DAY,HOUR,MINUTE,SECOND,QUARTER,DOW,ISODOW,DOY,WEEK, orEPOCH.timestamp— the timestamp to read from.
- The numeric value of the requested field.
Events grouped by hour of day
toStartOfMinute / toStartOfFiveMinutes / toStartOfTenMinutes / toStartOfFifteenMinutes / toStartOfHour / toStartOfDay
Round a timestamp down to the start of a fixed-length time bucket, from one minute up to a full day. Syntaxdatetime— the timestamp to round.
- The timestamp rounded down to the start of the chosen bucket.
Event volume per 15-minute bucket
toStartOfWeek / toStartOfMonth / toStartOfQuarter / toStartOfYear
Round a timestamp down to the start of a calendar period.toStartOfWeek uses a Monday-start week.
Syntax
datetime— the timestamp to round.
- The date at the start of the enclosing week, month, quarter, or year.
New users per month
toDate
Truncates a timestamp to its date component, dropping the time of day. Syntaxdatetime— the timestamp to truncate.
- The date portion of the input.
Distinct active days per event
timestamp subtraction
Subtracts one timestamp from another to measure the elapsed time between them. Syntaxtimestamp— the two timestamps to subtract; the second is subtracted from the first.
- An interval representing the elapsed time between the two timestamps.
Time between account creation and last update
timestampadd / timestampsub
Add or subtract a whole number of calendar units to or from a timestamp. Equivalent to adding or subtracting an interval, but the unit and count are passed as arguments. Syntaxunit— the calendar unit to add or subtract, such asday,hour,minute,second,week,month,quarter, oryear.count— the whole number of units to add (timestampadd) or subtract (timestampsub).timestamp— the timestamp to shift.
- The shifted timestamp.
Users created within 90 days
add_months
Shifts a date or timestamp by a whole number of months, clamping to the last valid day when the target month is shorter. Syntaxdatetime— the date or timestamp to shift.num_months— the number of months to add; negative values shift backward.
- The date or timestamp moved by
num_monthsmonths.
Users whose trial converts three months after signup
addDays / addHours / addMinutes / addSeconds / addWeeks / addQuarters / addYears
Add a whole number of a single time unit to a date or timestamp. Each function targets one unit. Syntaxdatetime— the date or timestamp to shift.n— the whole number of units to add.
- The date or timestamp shifted forward by
nof the given unit.
Expiry 14 days after an event
subtractDays / subtractHours / subtractMinutes / subtractSeconds / subtractWeeks / subtractMonths / subtractQuarters / subtractYears
Subtract a whole number of a single time unit from a date or timestamp. Each function targets one unit. Syntaxdatetime— the date or timestamp to shift.n— the whole number of units to subtract.
- The date or timestamp shifted backward by
nof the given unit.
Events in the last week
at time zone
Reinterprets a timestamp in a named time zone. Applied to a timestamp without time zone, it produces the corresponding instant; applied to a timestamp with time zone, it shows the wall-clock time in that zone. Syntaxtimestamp— the timestamp to reinterpret.zone— an IANA time-zone name such as'America/New_York'or'UTC'.
- The timestamp converted to the specified time zone.
Event time in New York local time
to_char
Formats a timestamp into a string using a format template. Syntaxtimestamp— the timestamp to format.format— the format template, for example'YYYY-MM-DD'or'HH24:MI:SS'.
- The formatted string.
Format the signup date as a string
make_date
Builds a date from separate year, month, and day fields. Syntaxyear— the year (integer).month— the month, 1 through 12.day— the day of month.
- The constructed date.
Events on or after the start of the fiscal year
toYYYYMM / toYYYYMMDD / toYYYYMMDDhhmmss
Encode a timestamp as a numeric key at month, day, or second precision. Useful for compact grouping and ordering. Syntaxdatetime— the timestamp to encode.
- An integer encoding the timestamp:
YYYYMM(for example202607),YYYYMMDD(for example20260716), orYYYYMMDDhhmmss.
Events grouped by month key
unix_timestamp
Converts a timestamp to the number of seconds since the Unix epoch. Syntaxdatetime— the timestamp to convert.
- The number of seconds since 1970-01-01 00:00:00 UTC, as an integer.
Epoch seconds for each signup
to_timestamp
Converts a Unix epoch value (seconds since 1970-01-01 00:00:00 UTC) into a timestamp. Syntaxunix_seconds— the number of seconds since the Unix epoch.
- The corresponding timestamp.
Convert a stored epoch property to a timestamp
dateName
Returns the name of a specified part of a date or timestamp as a string. Syntaxdatepart— the part to name, such as'year','quarter','month','week','dayofyear','day','weekday','hour','minute', or'second'.datetime— the date or timestamp to read from.
- The name of the requested part as a string, for example
'Monday'or'April'.
Events grouped by weekday name
monthName
Returns the full English name of the month for a date or timestamp. Syntaxdatetime— the date or timestamp to read from.
- The full month name as a string, for example
'January'.
Events grouped by month name
timeSlot
Rounds a timestamp down to the start of its half-hour slot. Syntaxdatetime— the timestamp to round.
- The timestamp rounded down to the nearest 30-minute boundary.
Event volume per half-hour slot
timeZoneOffset
Returns the offset from UTC, in seconds, for a timestamp, accounting for daylight saving time. Syntaxdatetime— the timestamp to evaluate.
- The offset from UTC in seconds.
UTC offset at event time
toISOWeek / toISOYear
Return the ISO 8601 week number and week-numbering year for a timestamp. Under ISO rules, a week belongs to the year that contains its Thursday. Syntaxdatetime— the timestamp to evaluate.
toISOWeekreturns the ISO week number, 1 through 53.toISOYearreturns the ISO week-numbering year.
Events grouped by ISO week
toWeek / toYearWeek
Return the week number, and the combined year-and-week, for a timestamp using ISO week numbering. Syntaxdatetime— the timestamp to evaluate.
toWeekreturns the week number.toYearWeekreturns an integer combining the year and week asYYYYWW.
Events per year-week
toLastDayOfMonth / toLastDayOfWeek
Return the last day of the calendar period containing a timestamp.toLastDayOfWeek uses a Monday-start week, so it returns the Sunday.
Syntax
datetime— the timestamp to evaluate.
- The date of the last day of the enclosing month or week.
Month-end date for each signup
toUnixTimestamp64Milli
Converts a high-precision timestamp to the number of milliseconds since the Unix epoch. Syntaxdatetime— the timestamp to convert.
- The number of milliseconds since 1970-01-01 00:00:00 UTC, as a 64-bit integer.
Epoch milliseconds for each event
yesterday
Returns the date of the day before today. Syntax- Yesterday’s date, with no time component.
Events that happened yesterday
from_utc_timestamp / to_utc_timestamp
Convert a timestamp between UTC and a named time zone.from_utc_timestamp reads the input as UTC and returns the wall-clock time in the target zone; to_utc_timestamp reads the input as local to the target zone and returns the equivalent UTC time.
Syntax
timestamp— the timestamp to convert.timezone— an IANA time-zone name such as'America/New_York'.
- The converted timestamp.
Show event time in the user's local zone
age
Returns the symbolic difference between two timestamps as years, months, and days. With a single argument, the difference is measured from the current date at midnight (PostgreSQL only). Syntaxtimestamp— with two arguments, the second is subtracted from the first. With one argument, the timestamp is subtracted fromcurrent_date.
- An interval expressed in years, months, and days.
Account age as years and months