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?
you can do this by
date("F j, Y", time() - 60 * 60 * 24);
or by
date("F j, Y", strtotime("yesterday"));
try this
$tz = new DateTimeZone('Your Time Zone');
$date = new DateTime($today,$tz);
$interval = new DateInterval('P1D');
$date->sub($interval);
echo $date->format('d.m.y');
?>
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.)
You can also do this using Carbon library:
Carbon::yesterday()->format('d.m.Y'); // '26.03.2019'
In other formats:
Carbon::yesterday()->toDateString(); // '2019-03-26'
Carbon::yesterday()->toDateTimeString(); // '2019-03-26 00:00:00'
Carbon::yesterday()->toFormattedDateString(); // 'Mar 26, 2019'
Carbon::yesterday()->toDayDateTimeString(); // 'Tue, Mar 26, 2019 12:00 AM'
Yesterday Date in PHP:
echo date("Y-m-d", strtotime("yesterday"));
try this
<?php
$yesterday = date(“d.m.Y”, time()-86400);
echo $yesterday;