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

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

    If you want a specific date in next month, you can do this:

    // Calculate the timestamp
    $expire = strtotime('first day of +1 month');
    
    // Format the timestamp as a string
    echo date('m/d/Y', $expire);
    

    Note that this actually works more reliably where +1 month can be confusing. For example...

    Current Day   | first day of +1 month     | +1 month
    ---------------------------------------------------------------------------
    2015-01-01    | 2015-02-01                | 2015-02-01
    2015-01-30    | 2015-02-01                | 2015-03-02  (skips Feb)
    2015-01-31    | 2015-02-01                | 2015-03-03  (skips Feb)
    2015-03-31    | 2015-04-01                | 2015-05-01  (skips April)
    2015-12-31    | 2016-01-01                | 2016-01-31
    

提交回复
热议问题