Click to See Complete Forum and Search --> : How to add one month to Now()? [MySQL & PHP5]


Shaitan00
April 6th, 2009, 12:56 AM
Within my PHP5 application I need to set an expiry date when inserting/updating into the MySQL database - but honestly I've got no clue how...
Specifically - it needs to be one month from the day of the insert/update (thus one month past Now())

Currently I've got the following working fine:
UPDATE item SET expdate=Now() WHERE pid=1;

Obviously this set the expdate to the current date, I've tried doing Now()+1 (didn't work), was looking into ADDDATE (couldn't get it to work), etc...

How, in MySQL, can I add 1 month to Now()?
Any help would be much appreciated.
Thanks,

davide++
April 6th, 2009, 02:35 AM
Hi all.
Standard SQL overloads operator + for dates, and day is the unit. So you should write


UPDATE item
SET expdate=Now() + 30
WHERE pid=1;


I hope this will help you.

Shuja Ali
April 6th, 2009, 02:35 AM
Looks like MySQl calls it DATE_ADD function.
Update ITEM Set EXPDATE = DATE_ADD(NOW(), INTERVAL 1 MONTH) Where PID = 1;