Andelas
Andelas

Reputation: 2052

php date() showing wrong day

Noticed that dates were off on a page and I can't figure out why.

Just doing this simple code

echo date("F m, Y: h:iA e");

Returns this:

July 07, 2013: 09:47PM America/New_York

The time is correct, the date is obviously behind (today being the 25th).

I checked the time on server

root@srv449 [~]# date
Thu Jul 25 21:48:42 EDT 2013

Any tips on where this could be thrown off? What's REALLY confusing me is that other pages where we use dates seem to be ok.

Also, doing

echo time();

returns

1374803608

which seems correct.

Upvotes: 2

Views: 2944

Answers (2)

user764357
user764357

Reputation:

You are outputing the month as the day here:

echo date("F m, Y: h:iA e");

It needs to be:

echo date("F d, Y: h:iA e");

Upvotes: 2

Jason McCreary
Jason McCreary

Reputation: 72971

m is month (which is 7 for July).

You want d (leading zeros) or j (without leading zeros):

echo date("F j, Y: h:iA e");

See date() format for more.

Upvotes: 4

Related Questions