Return the interval or exact number of days between two date-time values using built-in arithmetic or AGE().
PostgreSQL—on which ParadeDB is built—lets you subtract one date or timestamp from another. The result is an interval
, eliminating the need for a separate DATEDIFF
function.
Use the date
type or cast to ::date
before subtraction, then apply EXTRACT(day FROM ...)
or interval '1 day'
division.
SELECT (o.order_date::date - c.created_at::date) AS days_gap
FROM Customers c
JOIN Orders o ON o.customer_id = c.id;
AGE(later, earlier)
normalizes the interval into years, months, and days—helpful for customer anniversaries or product warranty checks.
See the next section for full syntax options, including interval extraction and epoch conversion.
No. Use date arithmetic or the AGE() function instead.
Cast both values to ::date
before subtraction, or convert them to the same time zone with AT TIME ZONE
.
Yes. Use AGE()
and extract year
and month
parts, or divide the day count by 30 if approximate values are acceptable.