Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find second and fourth saturday's of the month

How to find 2nd and 4th Saturday of the month. I wrote these lines:-

echo "may 2nd sat ".date('d', strtotime('may 2013 second saturday'));
echo '<br/>may 4th sat '.date('d', strtotime('may 2013 fourth saturday'));                                  
echo '<br/>june 2nd sat '.date('d', strtotime('june 2013 second saturday'));
echo '<br/>june 4th sat '.date('d', strtotime('june 2013 fourth saturday'));

It gives the following output :-

may 2nd sat 11
may 4th sat 25
june 2nd sat 15
june 4th sat 29

It gives correct answer in may month but not june 2013, in jun 1013 2nd and 4th saturday should be 8 and 22 respectively. How could I solve this issue.

like image 350
Maulik patel Avatar asked Jun 11 '13 06:06

Maulik patel


1 Answers

I'm not sure why yours won't work, but try this, it worked for me:

echo '<br/>june 2nd sat '.date('d', strtotime('second sat of june 2013'));
echo '<br/>june 4th sat '.date('d', strtotime('fourth sat of june 2013'));

It's based on the "first sat of July 2008" example in the PHP manual page

like image 134
periklis Avatar answered Oct 07 '22 19:10

periklis