Recall & Review
beginner
What does the AGE function in PostgreSQL do?
The AGE function calculates the difference between two dates or timestamps and returns the result as an interval showing years, months, and days.
Click to reveal answer
beginner
How do you use AGE to find the difference between the current date and a past date?
Use AGE(current_date, past_date). For example, AGE(current_date, '2000-01-01') returns the time passed since January 1, 2000.
Click to reveal answer
beginner
What is the output type of the AGE function in PostgreSQL?
The output is an interval type that shows the difference in years, months, days, and time components.
Click to reveal answer
intermediate
What happens if you use AGE with only one argument?
AGE with one argument returns the difference between the current date/time and the given timestamp.
Click to reveal answer
intermediate
Why is AGE preferred over simple subtraction for date differences?
AGE accounts for months and years properly, giving a human-readable difference, while subtraction returns just the number of days.
Click to reveal answer
What does AGE('2024-06-01', '2023-06-01') return?
✗ Incorrect
AGE returns the difference as an interval showing 1 year between the two dates.
Which data type does AGE return in PostgreSQL?
✗ Incorrect
AGE returns an interval type representing the difference between dates.
What is the result of AGE('2024-06-01') if today is '2024-06-10'?
✗ Incorrect
AGE with one argument returns the difference from the current date/time to the given date, which is 9 days.
If you subtract two dates directly (date1 - date2), what do you get?
✗ Incorrect
Direct subtraction returns the number of days as an integer, not a detailed interval.
Why might AGE('2024-06-01', '2023-12-01') return '6 mons' instead of '182 days'?
✗ Incorrect
AGE returns a human-readable interval counting months and years, not just total days.
Explain how the AGE function calculates the difference between two dates in PostgreSQL.
Think about how AGE shows time passed in years and months, not just days.
You got /4 concepts.
Describe the difference between using AGE and simple date subtraction for finding date differences.
Consider what each method returns and how it represents the difference.
You got /4 concepts.