The DateInterval class was introduced in PHP version 5.3.0 and its purpose is to represent a date interval. $yesterday = $yesterdayDT->format('Y-m-d') Get yesterday's date in a YYYY-MM-DD format. $yesterdayDT = $currentDate->sub(new DateInterval('P1D'))
Use the sub function to subtract a DateInterval Passing in the string yesterday to strtotime is essentially the same thing as subtracting -1 days from today’s date.Ī DateTime alternative, which you can use if your PHP version is 5.3.0 or above: //New DateTime object representing today's date. $yesterday = date('Y-m-d', strtotime('yesterday')) To get yesterday’s date, you can pass in the string “yesterday” to the strtotime function: //Yesterday