AdvancedDate & Time Functions

Find employees with work anniversaries this month

The query

SQL
SELECT
  first_name,
  last_name,
  hire_date,
  EXTRACT(YEAR FROM AGE(hire_date)) AS years_of_service,
  hire_date + MAKE_INTERVAL(years => EXTRACT(YEAR FROM AGE(hire_date))::INT + 1) AS next_anniversary
FROM employees
WHERE
  EXTRACT(MONTH FROM hire_date) = EXTRACT(MONTH FROM CURRENT_DATE)
  AND status = 'active'
ORDER BY EXTRACT(DAY FROM hire_date);
Tested against PostgreSQL 16

Note

MAKE_INTERVAL creates interval from parts. Work anniversary queries are common in HR systems.

Tables referenced