Get yesterday's date in PHP
Question:
How to get yesterday's date in PHP? Answer:
$yesterday = new DateTime('yesterday');
echo $yesterday->format('Y-m-d');
Description:
To get yesterday's date in PHP simply use the DateTime
class and instantiate it with the constructor parameter 'yesterday'
Then you can format the DateTime
object with the format
method.
Reference:
The DateTime constructor reference
Share "How to get yesterday's date in PHP?"
Related snippets:
- Add minutes to date time in PHP
- Add days to date in PHP
- Get same day in the next week in PHP
- Get time difference in minutes in PHP
- Convert date to timestamp in PHP
- Convert timestamp to DateTime in PHP
- Get the last day of a month from date in PHP
- Get the number of days between two dates in PHP
- Get yesterday's date in PHP
- Get tomorrow's date in PHP
- Get current time in PHP
- Get actual date in PHP
Tags:
get yesterdays date, date of yesterday, yesterday date, php, date, yesterday Technical term:
Get yesterday's date in PHP