Dates and times can be complicated. [[PostreSQL]] has a number of utilities that help store dates and times correctly and calculate time intervals or age.
```SQL
CREATE TABLE dates (
date DATE,
timestamp TIMESTAMP,
time_with_timezone TIMESTAMPTZ,
time TIME,
interval INTERVAL -- unique to Postgres
);
INSERT INTO dates (
date,
timestamp,
timestamp_with_timezone,
time,
interval
) VALUES (
DATE '2022-11-02',
'1999-01-08:04:05:06',
'1999-01-08:04:05:06',
'04:05:06')
'0000-00-07:00:00:00';
```
Postgres stores date/time values as [[UTC]]. If you run `SELECT NOW()` you will see the time is UTC, not local time.
Use [[EXTRACT]] to get a day, week, month, year, decade or century from a date. An alternative is [[DATE_PART]] or [[TO_CHAR]].
## time interval
See the [docs](https://www.postgresql.org/docs/current/datatype-datetime.html) for more detail.
```SQL
NOW() + INTERVAL '1 YEAR';
```
## age
Age returns a duration between now (by default) and a date.
```SQL
AGE(<birthday>)
AGE(birthday, NOW())::text
```