Adding days to $Date in PHP

前端 未结 9 2062
时光取名叫无心
时光取名叫无心 2020-11-22 09:32

I have a date returned as part of a mySQL query in the form 2010-09-17

I would like to set the variables $Date2 to $Date5 as follows:

$Dat

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 10:24

    Here is a small snippet to demonstrate the date modifications:

    $date = date("Y-m-d");
    //increment 2 days
    $mod_date = strtotime($date."+ 2 days");
    echo date("Y-m-d",$mod_date) . "\n";
    
    //decrement 2 days
    $mod_date = strtotime($date."- 2 days");
    echo date("Y-m-d",$mod_date) . "\n";
    
    //increment 1 month
    $mod_date = strtotime($date."+ 1 months");
    echo date("Y-m-d",$mod_date) . "\n";
    
    //increment 1 year
    $mod_date = strtotime($date."+ 1 years");
    echo date("Y-m-d",$mod_date) . "\n";
    

提交回复
热议问题