increment date by one month

前端 未结 18 2540
广开言路
广开言路 2020-11-27 04:14

Let\'s say I have a date in the following format: 2010-12-11 (year-mon-day)

With PHP, I want to increment the date by one month, and I want the year to be automatica

18条回答
  •  面向向阳花
    2020-11-27 04:35

    I use this way:-

     $occDate='2014-01-28';
     $forOdNextMonth= date('m', strtotime("+1 month", strtotime($occDate)));
    //Output:- $forOdNextMonth=02
    
    
    /*****************more example****************/
    $occDate='2014-12-28';
    
    $forOdNextMonth= date('m', strtotime("+1 month", strtotime($occDate)));
    //Output:- $forOdNextMonth=01
    
    //***********************wrong way**********************************//
    $forOdNextMonth= date('m', strtotime("+1 month", $occDate));
      //Output:- $forOdNextMonth=02; //instead of $forOdNextMonth=01;
    //******************************************************************//
    

提交回复
热议问题