emanuele pina
emanuele pina

Reputation: 57

Add int to date SQL

I have a table Scadenziario with many columns.

I want to add the column "Frequenza"(INT) to the column "preavviso" (DATE).

With the query

select ID, Scadenza, Frequenza
FROM scadenziario
WHERE Scadenza < '2018-12-11'

I'm going to select the row that i need

"frequenza" is an int that specify the number of day that will pass before renew the deadline ("scadenza")

How can i add "frequenza" to "Scadenza"?

For example

ID | Scadenza  | Frequenza
1  | 2018-12-1 | 20
2  | 2018-1-1  | 40

should become

ID | Scadenza   | Frequenza
1  | 2018-12-21 | 20
2  | 2018-2-11  | 40

Upvotes: 0

Views: 134

Answers (2)

jarlh
jarlh

Reputation: 44766

You can use DATE_ADD() function:

select ID, Scadenza, Frequenza, DATE_ADD( Scadenza, INTERVAL Frequenza DAY) 
FROM scadenziario
WHERE Scadenza < '2018-12-11'

Upvotes: 2

Yona
Yona

Reputation: 1

I didn't understand what you exactly what to do. But if I understand correctly this is what you need to do:

ALTER TABLE `scadenziario` 
ADD COLUMN `Frequenza ` INT NULL AFTER `scadenza `;

Upvotes: 0

Related Questions