JasonDavis
JasonDavis

Reputation: 48983

How to show yesterdays date in this format?

I know there is a lot of info on the neton how to show yesterdays date but I am unable to get any of them to work in this format

How do you show yesterdays date if todays date is in this format date('F jS, Y') ?

July 27th, 2009 should show July 26th, 2009

//Does not work
$yesterday = date('F jS, Y', mktime(0, 0, 0, date("F") , date("j") - 1, date("Y")));
echo $yesterday;

Upvotes: 0

Views: 984

Answers (2)

dusoft
dusoft

Reputation: 11479

easier: $yesterday = date('F jS, Y', time()-86400);

Upvotes: 2

Paolo Bergantino
Paolo Bergantino

Reputation: 488714

Use the very awesome strtotime:

$today = 'July 27th, 2009';
$yesterday = date('F jS, Y', strtotime('yesterday', strtotime($today)));
print $yesterday; // July 26th, 2009

Upvotes: 7

Related Questions