Date and Time Types in Postgres
When working with dates and time in PostgreSQL, understanding the available date/time types is useful. As a Postgres user, let’s explore these types in more detail.
1. Date Data Type
-
Date: Represents a date value (e.g., birthdays, deadlines).
-
Stored as 4 bytes.
-
Range: 4713 BC to 5874897 AD.
-
Example:
-
2. Time Data Type
-
Time: Represents a time-of-day value (e.g., appointment times).
-
Stored as 8 bytes.
-
Range: 00:00:00 to 24:00:00.
-
Example:
-
3. Timestamp Data Type
-
Timestamp: Represents a combined date and time value (e.g., event timestamps).
-
Stored as 8 bytes.
-
Range: 4713 BC to 294276 AD.
-
Example:
-
4. Timestamp with Time Zone Data Type
-
Timestamp with Time Zone (timestamptz): Includes time zone information.
-
Stored as 8 bytes.
-
Example:
-
5. Interval Data Type
-
Interval: Represents a duration of time (e.g., event duration).
-
Stored as 16 bytes.
-
Example:
-
Remember to adapt these examples to your specific use case. Happy querying!
For more detailed information, consult the official PostgreSQL documentation. If you have further questions, feel free to ask us on our Discord!