Adding days to $Date in PHP

前端 未结 9 1949
时光取名叫无心
时光取名叫无心 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:11

    You can also use the following format

    strtotime("-3 days", time());
    strtotime("+1 day", strtotime($date));
    

    You can stack changes this way:

    strtotime("+1 day", strtotime("+1 year", strtotime($date)));
    

    Note the difference between this approach and the one in other answers: instead of concatenating the values +1 day and , you can just pass in the timestamp as the second parameter of strtotime.

提交回复
热议问题