mike
mike

Reputation: 2760

How to find the current day of the year in PHP?

Is there a standard function in PHP that will find the day number of the year based on the current date?

Examples:

Jan 22nd = 22 
Feb 27th = 58
Mar 5th = 64

If there isn't a standard function, has anyone built anything similar that would handle the conversion? What all is involved?

Upvotes: 49

Views: 39748

Answers (3)

Mike
Mike

Reputation: 2593

date('z') + 1;

Documentation:

The day of the year (starting from 0)

https://www.php.net/manual/en/datetime.format.php

Upvotes: 98

pccFatMan
pccFatMan

Reputation: 109

// get day of year for 08 aug 2008
// result 221
echo date("z", mktime(0,0,0,8,8,2008))+1;

Upvotes: 10

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827316

Use the z format character of the date function:

 echo date('z'); // 22, based on the "current date"

Upvotes: 11

Related Questions