Lance
Lance

Reputation: 4820

Convert date integer to text?

Is there anyway to convert the value of idate("z") to a date format that reads the Day, Month, and Year? My code looks like this:

$date_int = idate("z");
$date_text = strtotime($date_int);
$date = date("l, F j, Y", $date_text);

For some reason, it's still echoing Thursday, January 1, 1970.

Any ideas?

Upvotes: 0

Views: 562

Answers (3)

Crashspeeder
Crashspeeder

Reputation: 4311

idate("z") is incorrect as that will return the day of the year. It seems like you want idate("U"), but in that case just use date() without the second parameter, it will assume time(). Example:

$date = date("l, F j, Y");

That should be all you need.

Upvotes: 1

Mike B
Mike B

Reputation: 32145

Assuming you want the date of the CURRENT YEAR:

$dayOfYear = 80;
print date("l, F j, Y", strtotime($dayOfYear - idate("z") . " day")); // Wednesday, March 21, 2012

$dayOfYear = 1;
print date("l, F j, Y", strtotime($dayOfYear - idate("z") . " day")) // Monday, January 2, 2012

Upvotes: 0

John Giotta
John Giotta

Reputation: 16934

idate("z") will only return the day of the year. Today being 74. strtotime will not understand 74 as a parsing format. Therefore date() fails all together.

Upvotes: 0

Related Questions