Reputation: 6805
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!
Upvotes: 1
Views: 133
Reputation: 30575
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.
Upvotes: 1
Reputation: 48314
I think this gets you what you want:
$i = (int) (($day_of_month + 6) / 7);
where $day_of_month
is from 1 to 31.
Upvotes: 2