|
-
April 6th, 2009, 12:56 AM
#1
How to add one month to Now()? [MySQL & PHP5]
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,
-
April 6th, 2009, 02:35 AM
#2
Re: How to add one month to Now()? [MySQL & PHP5]
Hi all.
Standard SQL overloads operator + for dates, and day is the unit. So you should write
Code:
UPDATE item
SET expdate=Now() + 30
WHERE pid=1;
I hope this will help you.
-
April 6th, 2009, 02:35 AM
#3
Re: How to add one month to Now()? [MySQL & PHP5]
Looks like MySQl calls it DATE_ADD function.
PHP Code:
Update ITEM Set EXPDATE = DATE_ADD(NOW(), INTERVAL 1 MONTH) Where PID = 1;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|