On this page
Kater SQL Functions Derive
KATER__PERIODS_SINCE
How many whole periods there are from the since date to this date.
Family: Derive
Syntax
KATER__PERIODS_SINCE(field, since, unit)Arguments
| Argument | Description |
|---|---|
field | The date to count to, such as an order date. |
since | The date to count from, such as the date a customer signed up. A date: a field, a grain of its date, such as KATER__MONTH(order_date), or a fixed day, such as ‘2024-02-01’::DATE. |
unit | The length of one period. One of 'day', 'week', 'month', 'quarter', 'year'. |
Returns
A whole number. It is negative where the date is before since. The field menu writes @format number(0) beside it.
Usage notes
- Both dates count from the start of their period, so from 31 January to 1 February is 1 month.
- A cohort’s age is this count, such as months since the first order.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.order_id AS "Order ID", customers.signup_date AS "Signup Date", orders.order_date AS "Order Date", KATER__PERIODS_SINCE(orders.order_date, customers.signup_date, 'month') AS "Months Since Signup"FROM kater_dataset.orders AS ordersJOIN kater_dataset.customers AS customers ON orders.customer_id = customers.customer_idWHERE KATER__IS_NOT_NULL(customers.signup_date)ORDER BY 1LIMIT 3| Order ID | Signup Date | Order Date | Months Since Signup |
|---|---|---|---|
| O00000 | 2024-04-12 | 2025-05-26 | 13 |
| O00001 | 2024-08-17 | 2025-11-28 | 15 |
| O00002 | 2025-01-12 | 2025-07-25 | 6 |
Compiles to
DATE_DIFF( 'MONTH', CAST(DATE_TRUNC('MONTH', customers.signup_date) AS DATE), CAST(DATE_TRUNC('MONTH', orders.order_date) AS DATE))DATEDIFF( MONTH, CAST(DATE_TRUNC('MONTH', customers.signup_date) AS DATE), CAST(DATE_TRUNC('MONTH', orders.order_date) AS DATE))See also
- Groups and flags
- Other functions in Derive:
KATER__MAP,KATER__BUCKET