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

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

    Be careful, because sometimes strtotime("+1 months") can skip month numbers.

    Example:

    $today = date("Y-m-d"); // 2012-01-30
    $next_month = date("Y-m-d", strtotime("$today +1 month"));
    

    If today is January, next month should be February which has 28 or 29 days, but PHP will return March as next month, not February.

提交回复
热议问题