'Date_Add Interval
The following MySQL works a dream when inserting rows -
INSERT INTO seo_task (column1, column2)VALUES ('value', DATE_ADD(NOW(), INTERVAL 1 MONTH))
How can I insert a row that would be 1 Month & 1 Day? for example
INSERT INTO seo_task (column1,column2)VALUES ('value', DATE_ADD(NOW(), INTERVAL 1 DAY 1 MONTH))
Obviously this example wont work, but this is what I am tryign to achieve. Can anyone shed some light for me?
Thanks
Solution 1:[1]
Just apply the second DATE_ADD to the result of the first
INSERT INTO seo_task (column1,column2)VALUES ('value', DATE_ADD(DATE_ADD(NOW(), INTERVAL 1 DAY), INTERVAL 1 MONTH))
This is exactly the same as the above example, just broken out a bit for readability
INSERT INTO seo_task (
column1,
column2
) VALUES (
'value',
DATE_ADD(
DATE_ADD(
NOW(),
INTERVAL 1 DAY
),
INTERVAL 1 MONTH
)
)
Solution 2:[2]
Very old question, but the second simplest way to add a compound interval is jut to keep adding intervals.
I this case, the solution becomes:
INSERT INTO seo_task (column1,column2)
VALUES ('value', NOW() + INTERVAL 1 DAY + INTERVAL 1 MONTH);
In some other DBMS, such as PostgreSQL and Oracle, you can have a more compounded interval such as interval '1 month 1 day', but not in MySQL.
MySQL does sometimes have a simpler solution to the above. There are compound units such as interval '3 3' year_month, but, alas, not for month and day.
Solution 3:[3]
Hope this helps
INSERT INTO seo_task (column1,column2)VALUES
('value', DATE_ADD(DATE_ADD(NOW(), INTERVAL 1 MONTH),INTERVAL 1 DAY) );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simon at My School Portal |
| Solution 2 | Manngo |
| Solution 3 | Naveen Kumar |
