EasyDate & Time Functions
Show age of each customer account
The query
SQL
SELECT
name,
joined_at,
CURRENT_DATE - joined_at::DATE AS days_as_customer,
EXTRACT(YEAR FROM AGE(joined_at)) AS years_customer,
CASE
WHEN CURRENT_DATE - joined_at::DATE < 90 THEN 'New'
WHEN CURRENT_DATE - joined_at::DATE < 365 THEN 'Growing'
ELSE 'Loyal'
END AS loyalty_segment
FROM customers
ORDER BY joined_at;Note
“Customer age segmentation. Date arithmetic directly returns integer days in PostgreSQL.