How do I get next month date from today's date and insert it in my database?

后端 未结 13 750
我寻月下人不归
我寻月下人不归 2021-02-01 15:07

I have two columns in my db: start_date and end_date, which are both DATE types. My code is updating the dates as follows:



        
13条回答
  •  耶瑟儿~
    2021-02-01 15:23

    You do not actually need PHP functions to achieve this. You can already do simple date manipulations directly in SQL, for example:

    $sql1 = "
        UPDATE `users` SET 
        `start_date` = CURDATE(), 
        `end_date` = DATE_ADD(CURDATE(), INTERVAL 1 MONTH)  
        WHERE `users`.`id` = '" . $id . "';
    ";
    

    Refer to http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_addtime

提交回复
热议问题