If you need the difference between two timestamps, which function would you apply?

Prepare for your Database Systems Test. Use flashcards and multiple-choice questions, each question with hints and explanations. Ace your exam!

Multiple Choice

If you need the difference between two timestamps, which function would you apply?

Explanation:
The difference between two timestamps is represented as an interval, and the function that yields that elapsed amount is designed specifically for that purpose. In PostgreSQL, age takes two timestamps and returns the interval that separates them. That makes it the natural tool to use when you need the elapsed time between two moments. For example, age(timestamp1, timestamp2) gives you how long ago timestamp2 was from timestamp1 (or vice versa, depending on order). Other options don’t fit as well. NOW is just the current moment, not a difference. current_date or current_time return the present date or time, not how much time has passed. Date_Trunc rounds a timestamp down to a specified unit (like the start of the day or hour) and does not compute a duration. So, age is the best answer because it directly computes the elapsed interval between two timestamps.

The difference between two timestamps is represented as an interval, and the function that yields that elapsed amount is designed specifically for that purpose. In PostgreSQL, age takes two timestamps and returns the interval that separates them. That makes it the natural tool to use when you need the elapsed time between two moments. For example, age(timestamp1, timestamp2) gives you how long ago timestamp2 was from timestamp1 (or vice versa, depending on order).

Other options don’t fit as well. NOW is just the current moment, not a difference. current_date or current_time return the present date or time, not how much time has passed. Date_Trunc rounds a timestamp down to a specified unit (like the start of the day or hour) and does not compute a duration.

So, age is the best answer because it directly computes the elapsed interval between two timestamps.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy