views:

17

answers:

2

I've seen lots of "Date" related questions here, however, I haven't been able to find one that calculates this:

I am trying to figure out the numerical value of a given date string. For example:

 $date = "2010-09-01";

Given the date above, how might I be able to determine that this is the "1st" Wednesday of the month.

I know that: date("l", $date); will tell me that it's a Wednesday, but how do I determine if it's the 1st, 2nd, 3rd, or 4th Wednesday of the Month?

Any help on this would be great!

+1  A: 

I think this gets you what you want:

$i = (int) (($day_of_month + 6) / 7);

where $day_of_month is from 1 to 31.

konforce
Thanks konforce. That was it!
Dodinas
+1  A: 

You just need a little bit of maths.

If the day of the month is < 8, then it's the first Wednesday. Or Friday. Or Monday. Or Saturday. So if it's between 7 and 15, then it's the second whatever. And so on. @konforce has posted the actual formula.

staticsan