Complete the code to calculate the age difference between two dates using the AGE function.
SELECT AGE([1], '2023-01-01') AS difference;
The AGE function calculates the interval between two dates. Here, the first argument should be a later date to get a positive difference.
Complete the code to calculate the age difference between the current date and a given birthdate.
SELECT AGE(CURRENT_DATE, [1]) AS age;The AGE function here calculates the age from the birthdate to today. The birthdate must be in the past.
Fix the error in the code to correctly calculate the age difference between two timestamps.
SELECT AGE([1], '2023-06-01 12:00:00') AS diff;
The AGE function returns the interval between the first and second timestamp. To get a positive difference, the first timestamp should be later.
Fill both blanks to calculate the age difference between two dates and filter results where the difference is more than 1 year.
SELECT AGE([1], [2]) AS age_diff FROM events WHERE AGE([1], [2]) > INTERVAL '1 year';
The AGE function calculates the interval between the two dates. Filtering for intervals greater than 1 year requires the dates to be at least one year apart.
Fill all three blanks to create a query that calculates the age difference between two timestamps, extracts the year part, and filters for differences of 5 years or more.
SELECT EXTRACT(year FROM AGE([1], [2])) AS years_diff FROM users WHERE EXTRACT(year FROM AGE([1], [2])) >= [3];
The AGE function calculates the interval between two timestamps. EXTRACT(year FROM ...) gets the year part of the interval. Filtering for differences of 5 years or more requires the threshold 5.