[SOLVED] Date_Add Interval

Issue

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

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
    )
)

Answered By – Simon at My School Portal

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *