0
0
PostgreSQLquery~5 mins

AGE function for differences in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A365 days
B1 year
C12 months
D30 days
Which data type does AGE return in PostgreSQL?
ADate
BInteger
CInterval
DTimestamp
What is the result of AGE('2024-06-01') if today is '2024-06-10'?
A9 days
B10 days
C1 day
D0 days
If you subtract two dates directly (date1 - date2), what do you get?
ANumber of days as an integer
BTimestamp
CInterval with years and months
DString describing difference
Why might AGE('2024-06-01', '2023-12-01') return '6 mons' instead of '182 days'?
AAGE rounds to nearest day
BAGE returns seconds
CAGE only works with years
DAGE counts months and years, not just 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.