What data type in PostgreSQL stores only the date without time?
The DATE type stores only the date (year, month, day) without any time information.
Click to reveal answer
beginner
Which PostgreSQL data type stores time of day without a date?
The TIME type stores the time of day (hours, minutes, seconds) without any date.
Click to reveal answer
intermediate
What is the difference between TIMESTAMP and TIMESTAMPTZ in PostgreSQL?
TIMESTAMP stores date and time without time zone information. TIMESTAMPTZ stores date and time with time zone awareness, automatically converting to UTC internally.
Click to reveal answer
intermediate
How does PostgreSQL handle time zones with the TIMESTAMPTZ type?
PostgreSQL converts TIMESTAMPTZ values to UTC internally and adjusts them to the client's time zone on retrieval, ensuring correct local time display.
Click to reveal answer
beginner
What format does PostgreSQL use to input and output DATE and TIME types?
PostgreSQL uses ISO 8601 format by default: - DATE: 'YYYY-MM-DD' - TIME: 'HH:MM:SS' - TIMESTAMP: 'YYYY-MM-DD HH:MM:SS' optionally with time zone.
Click to reveal answer
Which PostgreSQL type would you use to store just the time of day?
ADATE
BTIME
CTIMESTAMP
DTIMESTAMPTZ
✗ Incorrect
TIME stores only the time of day without any date.
What does TIMESTAMPTZ store that TIMESTAMP does not?
ATime zone information
BTime only
CMilliseconds precision
DDate only
✗ Incorrect
TIMESTAMPTZ stores timestamp with time zone information; TIMESTAMP does not.
How does PostgreSQL display TIMESTAMPTZ values to users?
AAlways in UTC
BWithout any time zone adjustment
CIn the server's local time zone
DIn the client's time zone
✗ Incorrect
TIMESTAMPTZ values are converted to the client's time zone on retrieval.
Which format is the default for inputting a DATE in PostgreSQL?
AYYYY-MM-DD
BMM-DD-YYYY
CDD-MM-YYYY
DYYYY/DD/MM
✗ Incorrect
PostgreSQL uses ISO 8601 format 'YYYY-MM-DD' for DATE.
If you want to store a date and time without time zone, which type do you choose?
ADATE
BTIME
CTIMESTAMP
DTIMESTAMPTZ
✗ Incorrect
TIMESTAMP stores date and time without time zone information.
Explain the differences between DATE, TIME, TIMESTAMP, and TIMESTAMPTZ types in PostgreSQL.
Think about what each type includes and how time zones are handled.
You got /4 concepts.
Describe how PostgreSQL handles time zones when using the TIMESTAMPTZ type.
Consider storage and display differences.
You got /3 concepts.
Practice
(1/5)
1. Which PostgreSQL data type should you use to store only the date without any time information?
easy
A. TIMESTAMP
B. TIME
C. INTERVAL
D. DATE
Solution
Step 1: Understand the data types
DATE stores only the calendar date (year, month, day) without time.
Step 2: Match the requirement
Since we want only the date without time, DATE is the correct choice.
Final Answer:
DATE -> Option D
Quick Check:
Date only = DATE [OK]
Hint: Use DATE for day only, no time needed [OK]
Common Mistakes:
Choosing TIMESTAMP which includes time
Using TIME which stores only time
Confusing INTERVAL with date storage
2. Which of the following is the correct way to declare a column named created_at that stores date and time with time zone in PostgreSQL?
easy
A. created_at TIMESTAMP WITH TIME ZONE
B. created_at TIMESTAMP
C. created_at DATE WITH TIME ZONE
D. created_at TIME WITH TIME ZONE
Solution
Step 1: Identify the correct type for date and time with time zone
PostgreSQL uses TIMESTAMP WITH TIME ZONE to store both date and time including time zone info.
Step 2: Check the options
created_at TIMESTAMP WITH TIME ZONE matches the correct syntax and type. The other options are either missing time zone or invalid.
Final Answer:
created_at TIMESTAMP WITH TIME ZONE -> Option A
Quick Check:
Date & time + time zone = TIMESTAMP WITH TIME ZONE [OK]
Hint: Use TIMESTAMP WITH TIME ZONE for date, time, and zone [OK]
Common Mistakes:
Using TIMESTAMP without time zone when zone is needed
Trying to add time zone to DATE or TIME types
Incorrect syntax like DATE WITH TIME ZONE
3. Given the table events(event_time TIMESTAMP) and the query: SELECT event_time::DATE FROM events WHERE event_time > '2024-01-01 12:00:00'; What will be the output type of the query?
medium
A. TIMESTAMP values
B. TIME values
C. DATE values
D. TEXT values
Solution
Step 1: Understand the cast operation
The ::DATE casts the TIMESTAMP to DATE, removing time part.
Step 2: Analyze the query output
The SELECT returns only the date part of event_time, so output type is DATE.
Final Answer:
DATE values -> Option C
Quick Check:
CAST TIMESTAMP to DATE = DATE output [OK]
Hint: Casting TIMESTAMP::DATE returns only date part [OK]
Common Mistakes:
Assuming output remains TIMESTAMP
Thinking output is TIME only
Confusing cast with string conversion
4. You wrote this query: SELECT event_time + '1 day' FROM events; But it gives an error. What is the likely cause?
medium
A. The string '1 day' must be cast to INTERVAL before adding
B. You cannot add intervals to TIMESTAMP in PostgreSQL
C. You must use DATE type for adding days
D. The column event_time is not a date or timestamp
Solution
Step 1: Understand adding intervals to timestamps
In PostgreSQL, you add intervals to timestamps, but the interval must be of type INTERVAL.
Step 2: Identify the error cause
The string '1 day' is text and must be cast to INTERVAL using '1 day'::INTERVAL or INTERVAL '1 day'.
Final Answer:
The string '1 day' must be cast to INTERVAL before adding -> Option A
Quick Check:
Add INTERVAL to TIMESTAMP, cast string first [OK]
Hint: Cast '1 day' to INTERVAL before adding to timestamp [OK]
Common Mistakes:
Adding string directly without casting
Assuming TIMESTAMP + string works
Using DATE type incorrectly
5. You want to store event start times in UTC but display them in users' local time zones. Which PostgreSQL data type and function combination is best to store and convert these times?
hard
A. Store as TIMESTAMP and use AT TIME ZONE to convert
B. Store as TIMESTAMP WITH TIME ZONE and use AT TIME ZONE to convert
C. Store as TIME and use SET TIMEZONE to convert
D. Store as DATE and use TIMEZONE() to convert
Solution
Step 1: Choose the correct storage type
TIMESTAMP WITH TIME ZONE stores the exact moment in time with zone info, ideal for UTC storage.
Step 2: Use conversion function
AT TIME ZONE converts stored UTC times to users' local time zones for display.
Final Answer:
Store as TIMESTAMP WITH TIME ZONE and use AT TIME ZONE to convert -> Option B
Quick Check:
Use TIMESTAMP WITH TIME ZONE + AT TIME ZONE for zone conversion [OK]
Hint: Use TIMESTAMP WITH TIME ZONE + AT TIME ZONE for conversions [OK]
Common Mistakes:
Storing as TIMESTAMP without time zone loses zone info
Using DATE or TIME types which lack full timestamp info
Confusing SET TIMEZONE session setting with conversion
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.