PHP Date Function Seven days previous

前端 未结 2 614
小鲜肉
小鲜肉 2020-12-05 17:27

I am trying to use PHP\'s Date Function to get the date of 7 days earlier in YYYY-MM-DD format.

date(\'Y-m-d\');

when i try



        
2条回答
  •  被撕碎了的回忆
    2020-12-05 17:49

    With this, as with all PHP date stuff, it's nicer to use the DateTime class.

    $date = new DateTime('7 days ago');
    echo $date->format('Y-m-d');
    

提交回复
热议问题