How to add/subtract a day

719 Views Asked by At

How can I subtract (or add) days from a dateandtime or smalldatetime date in Web SQL? I have tried searching for it, but couldn't find anything.

The solutions that exist are all for SQL and MySQL.

I have tried: DATEADD (SQL), and DATE_ADD/DATE_SUB (MySQL) functions.

Both are giving errors (even when I copy paste simple example statements), when I use them on my web page.

1

There are 1 best solutions below

6
Kevin Miranda On BEST ANSWER

Try (change now for te time string, or leave now to add or substract from today)

SELECT date('now','+1 day'); or SELECT date('now','-1 day');

EDIT:

If you want to add or substract to an specific day, you would need to format the date as following

YYYY-MM-DD HH:MM:SS

then you could use date or datetime and add/substract the day. Using the data from the comment:

SELECT DATE('2017-08-24 09:05:00','-1 days') --returns 2017-08-23
SELECT DATETIME('2017-08-24 09:05:00','+1 days'); --returns 2017-08-25 09:05:00