Articles Cookbook
Back to list
SQLite

How to Get Yesterday’s Date in SQLite

Database:

Operators:

DATE()

Problem:

You would like to display yesterday's date (without time) in an SQLite database.

Solution 1:

SELECT DATE('now','-1 day') AS yesterday_date;

Assuming today is 2020-09-24, the result is:

yesterday_date
2020-09-23

Discussion:

To get yesterday's date, you need to subtract one day from today. Use now() to get today's date. In SQLite, you can subtract or add any number of days, months, etc., using the DATE() function. Here, since you need to subtract one day, you use DATE('now','-1 day') to get yesterday’s date.

You can go back by any time interval just as easily. As an example, here is how you would go back by five months and three days.

SELECT DATE('now', '-5 months', '-3 days') AS modified_date;

You can also calculate tomorrow's date. To do so, you need to add one day.

SELECT DATE('now', '+1 day') AS tomorrow_date;

Recommended courses:

Recommended articles:

See also:

go to top