php - add + 7 days to date format mm dd, YYYY

前端 未结 7 463
野的像风
野的像风 2021-01-31 01:48

I have date of this format March 3, 2011 in database and I need to extend it with 7 days. I mean

 $date = $date + 7
. Is there any build in function to do that ?

7条回答
  •  醉酒成梦
    2021-01-31 02:23

    The "+1 month" issue with strtotime

    As noted in several blogs, strtotime() solves the "+1 month" ("next month") issue on days that do not exist in the subsequent month differently than other implementations like for example MySQL.

    $dt = date("Y-m-d");
    echo date( "Y-m-d", strtotime( "$dt +1 day" ) ); // PHP:  2009-03-04
    echo date( "Y-m-d", strtotime( "2009-01-31 +2 month" ) ); // PHP:  2009-03-31
    

提交回复
热议问题