Skip to main content

Datetime Operators

Datetime operators allow arithmetic operations on date and timestamp values. These operators enable adding or subtracting intervals from datetime values and calculating differences between datetime values.

Supported Operations

Operation

Result Type

Description

DATE + INTERVAL

TIMESTAMP

Add an interval to a date

TIMESTAMP + INTERVAL

TIMESTAMP

Add an interval to a timestamp

INTERVAL + INTERVAL

INTERVAL

Add an interval to another interval

DATE + TIME

TIMESTAMP

Combine a date and time into a timestamp

Examples

Adding Intervals to Dates

-- Example 1: Add days to a date
> SELECT DATE '2025-01-15' + INTERVAL '10' DAY;
2025-01-25 00:00:00

-- Example 2: Add months to a date
> SELECT DATE '2025-01-15' + INTERVAL '3' MONTH;
2025-04-15 00:00:00

-- Example 3: Add years to a date
> SELECT DATE '2025-01-15' + INTERVAL '2' YEAR;
2027-01-15 00:00:00

Adding Intervals to Timestamps

-- Example 4: Add hours to a timestamp
> SELECT TIMESTAMP '2025-01-15 10:30:00' + INTERVAL '5' HOUR;
2025-01-15 15:30:00

-- Example 5: Add days and hours to a timestamp
> SELECT TIMESTAMP '2025-01-15 10:30:00' + INTERVAL '1 12:00:00' DAY TO SECOND;
2025-01-16 22:30:00

Combining Date and Time

-- Example 8: Combine date and time
> SELECT DATE '2025-01-15' + TIME '14:30:00';
2025-01-15 14:30:00

See Also