Add days to a date in PHP

前端 未结 7 1820
情深已故
情深已故 2020-12-15 08:42

Is there any php function available where I can add days to a date to make up another date? For example, I have a date in the following format: 27-December-2011

If I

相关标签:
7条回答
  • 2020-12-15 09:06
    $registered = $udata->user_registered;
    $registered = date( "d m Y", strtotime( $registered ));
    $challanexpiry = explode(' ', $registered);
    $day   = $challanexpiry[0];
    $month = $challanexpiry[1];
    $year  = $challanexpiry[2];
    $day = $day+10;
    $bankchallanexpiry = $day . " " . $month . " " . $year;
    
    0 讨论(0)
  • 2020-12-15 09:10

    Try this

    $add_days = 7;
    $date = date('Y-m-d',strtotime($date) + (24*3600*$add_days));
    
    0 讨论(0)
  • 2020-12-15 09:10

    You can use the add method of DateTime. Anyway this solution works for php version >= 5.3

    0 讨论(0)
  • 2020-12-15 09:14
    $date = new DateTime('27-December-2011');
    $date->add(new DateInterval('P7D'));
    echo $date->format('d-F-Y') . "\n";
    

    Change the format string to be whatever you want. (See the documentation for date()).

    0 讨论(0)
  • 2020-12-15 09:18

    Look at this simple snippet

    $date = date("Y-m-d");// current date
    
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
    
    0 讨论(0)
  • 2020-12-15 09:24

    Actually it's easier than all that.

    $some_var = date("Y-m-d",strtotime("+7 day"))
    

    You can use a variable instead of the string, of course. It will be great if the people answering the questions, won't complicate things. Less code, means less time to waste on the server ;).

    0 讨论(0)
提交回复
热议问题