SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find second Saturday bug?

    I have the following php routine that is supposed to find the second saturday in june of any given year

    Code:
    $month = 6;   // should always be june
    $year = date("Y"); 
    echo '<br>Show Date: ' . date('F',strtotime('Second Saturday '.date('F o', @mktime(0,0,0, $month, 1, $year))));
    echo ' ' . date('j',strtotime('Second Saturday '.date('F o', @mktime(0,0,0, $month, 1, $year))));
    echo ', ' . date('Y',strtotime('Second Saturday '.date('F o', @mktime(0,0,0, $month, 1, $year)))) ;	
    echo '<br>';
    //
    However, while testing, I add one to the year ($year = date("Y") + 1 and it shows the 15th of June, 2013. But the second saturday is the 8th since the 1st in 2013 is the 1st saturday. How to fix this????

    E

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,267
    Mentioned
    116 Post(s)
    Tagged
    1 Thread(s)
    You should be able to do this:
    PHP Code:
    $year date("Y");
    $secondSaturday strtotime('+1 week sat june ' $year); 
    Attribution: I adapted this from this thread over on SO. I knew there was a way to do it, but I had forgotten the syntax....googling did the rest.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •