CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    429

    Question 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,

  2. #2
    Join Date
    Jun 2006
    Posts
    437

    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.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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 MONTHWhere 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
  •  





Click Here to Expand Forum to Full Width

Featured