how to get date of yesterday using php?

前端 未结 9 1638
悲&欢浪女
悲&欢浪女 2021-01-30 04:51

I want to get the yesterday date using specific date format in php this is the format:

$today = date(\"d.m.Y\"); //15.04.2013

Is it possible?

9条回答
  •  长发绾君心
    2021-01-30 05:23

    If you define the timezone in your PHP app (as you should), which you can do this way:

    date_default_timezone_set('Europe/Paris');
    

    Then it's as simple as:

    $yesterday = new DateTime('yesterday'); // will use our default timezone, Paris
    echo $yesterday->format('Y-m-d'); // or whatever format you want
    

    (You may want to define a constant or environment variable to store your default timezone.)

提交回复
热议问题