Add Days to a Date in SQLite

In SQLite, we can use the DATE() function to add a given number of days to a date.

If we’re dealing with datetime values, we can use the DATETIME() function.

Example

Here’s an example that uses the DATE() function:

SELECT DATE('2050-08-21', '+10 days');

Result:

2050-08-31

We can subtract the amount by replacing + with -.

Omitting + results in the amount being added, as if we’d used +:

SELECT DATE('2050-08-21', '10 days');

Result:

2050-08-31

We can specify the days in plural or non-plural form. That is, day is equivalent to days:

SELECT DATE('2050-08-21', '+10 day');

Result:

2050-08-31

The DATETIME() Function

Here’s an example that demonstrates how to use the DATETIME() function to add ten days to a datetime value:

SELECT DATETIME('2050-08-21', '+10 days');

Result:

2050-08-31 00:00:00

In this case, I passed exactly the same value as in the previous example. However, the function returned a datetime value.

Here it is with another datetime value:

SELECT DATETIME('2050-08-21 18:30:45', '+10 days');

Result:

2050-08-31 18:30:45

And here’s an example of adding a day to the date based on a number of hours:

SELECT DATETIME('2050-08-21 18:30:45', '+24 hours');

Result:

2050-08-22 18:30:45