tags:

views:

40

answers:

4

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?

A: 

under http://php.net/date you will find the exact format for that.

Itay Moav
+4  A: 

date('z') + 1;

Mike
the `time()` is not needed. He asks about current date.
Itay Moav
Very true. Fixed that and added a +1 to adjust for him starting from 1 instead of 0.
Mike
Perfect, Thanks!
mike
+1  A: 

Use the z format character of the date function:

 echo date('z'); // 22, based on the "current date"
CMS
who gave this a down rating? it's the right answer.
John Conde
You have to add 1, though, since the value returned is zero-based.
Joey
+1  A: 

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

pccFatMan