Add Days to a Date in PostgreSQL

The + operator allows us to add one or more days to a given date in PostgreSQL. We have a few options when it comes to specifying the actual number of days.

Examples

Here are some examples that demonstrate the various options for specifying the number of days to add to the date.

Specify an integer:

SELECT date '2030-05-10' + 5;

Result:

2030-05-15

We can also do it like this:

SELECT date '2030-05-10' + integer '5';

Result:

2030-05-15

By specifying an integer of 5, five days were added to the date.

Another way to do it is to specify an interval:

SELECT date '2030-05-10' + interval '1 day';

Result:

2030-05-11 00:00:00

This also works in plural form:

SELECT date '2030-05-10' + interval '5 days';

Result:

2030-05-15 00:00:00

Negative Values

We can also perform date arithmetic with negative values. If we use a negative value with the + sign, then the specified number of days will be subtracted from the date. But if we use it with the - sign, then it will be added to the date.

Example:

SELECT date '2030-05-10' - interval '-5 days';

Result:

2030-05-15 00:00:00

Same result as before.

The same holds true when using the integer option:

SELECT date '2030-05-10' - integer '-5';

Result:

2030-05-15