How do I form an SQL query to show entire column of dates with modified values?

dba.stackexchange https://dba.stackexchange.com/questions/254010

  •  18-02-2021
  •  | 
  •  

Вопрос

Assume that I have a table Purchases with column named PurchaseDate and with data format of 'YYYY-MM-DD HH:MI:SS'.
Suppose that I want to see the entire column of dates with the days increasing by 5.

Suppose I form the query in the following way:

SELECT PurchaseDate+5 FROM Purchases; 

The result will be given in a form of single numbers, and the increased part will be seconds instead of days.
I.e.: This 1982-09-07 00:00 will turn into this 198209070005.

How do I form the right standard SQL query?

UPDATE: I've got answer. Thanks.

-- this will work for standard SQL:

SELECT PurchaseDate, PurchaseDate + INTERVAL 5 DAY FROM Purchases;

-- this will work for MySQL:

SELECT PurchaseDate, ADDDATE(PurchaseDate, INTERVAL 10 DAY) FROM Purchases; 
Это было полезно?

Решение

Asuming the column has a datetime type, simply:

SELECT PurchaseDate + INTERVAL 5 DAY FROM

If it was a string type, you would have to parse it first.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с dba.stackexchange
scroll top