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

后端 未结 13 821
我寻月下人不归
我寻月下人不归 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

    The accepted answer works only if you want exactly 31 days later. That means if you are using the date "2013-05-31" that you expect to not be in June which is not what I wanted.

    If you want to have the next month, I suggest you to use the current year and month but keep using the 1st.

    $date = date("Y-m-01");
    $newdate = strtotime ( '+1 month' , strtotime ( $date ) ) ;
    

    This way, you will be able to get the month and year of the next month without having a month skipped.

提交回复
热议问题