Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Bakersfield, CA
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    first wednesdays and first thursday of the month

    I've been having some trouble with a script that is suppose to seemly to do something simple but its actually been quite difficult. Let me try to explain:

    The FIRST FRIDAY of each month, lets say a meeting is held.
    This group has online registration for this meeting. The WEDNESDAY & THURSDAY prior to the first Friday, registration for the meeting must be closed. After those wed and thurs, they would like to accept registration again (yes, beginning the first friday)

    Hopefully that's understandable? So I came up with this:

    PHP Code:
    <!-- determines first Wednesday and first Thursday of the month to echo something different than the rest of the days of the month. -->
    <?php
    $firstwed 
    strtotime("first Wednesday, first Thursday"date("F Y"));
    $now strtotime('today'); 

    if( 
    $firstwed == $now) {
      echo 
    "Registration is closed until our next event!";
      
    // do something
    } else {
      echo 
    'REGISTER AND PAY ONLINE HERE';
      
    // do something else
    }
    ?>
    But then soon realized, that didn't work. There's a few problems with the "first Thursday", right? Plus, the fact that those Wednesdays and Thursdays wont trigger like I would need if the first Friday ends up being, lets say, the 2nd.

    Second attempt, but this broke my page and half of the content went blank:

    PHP Code:
    // get date object for today
    $today = new DateTime();

    // get the date object for the first friday of the current month
    $ffstr 'First Friday of ' date('F') .' 'date('Y');
    $first_friday = new DateTime($ffstr);

    // create a cutoff date object two days before the first friday
    $cutoff_date = clone $first_friday;
    $cutoff_date->sub(new DateInterval('P2D'));

    // compare today's date to the cutoff date/first friday date
    if ($today $cutoff_date || $today $first_friday) {
      echo 
    'REGISTER AND PAY ONLINE HERE';
    } else {
      echo 
    "Registration is closed until our next event!";


    Should I be going about this a different way? I thought is was going to be simple, but now it's getting to be a headache.
    Last edited by gstricklind; 01-19-2012 at 09:29 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    First Friday OF a month will not work. OF is not a valid specifier.
    What will work is 'First friday January 2012' for example.
    DateInterval will only work on PHP 5.3.1+ systems. There is also no need to really use it for this task.
    PHP Code:
    $ff strtotime('first friday ' date('F Y'));
    $twoDaysPast strtotime('-2 day'$ff);
    $oneDaysPast strtotime('-1 day'$ff); 
    Simple as that.

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Bakersfield, CA
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok great. Thanks! I'm sorry, I'm still trying to get a handle on this PHP stuff.. what would the rest of the code look like now? Thanks for your help!

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by Fou-Lu View Post
    First Friday OF a month will not work. OF is not a valid specifier.
    What will work is 'First friday January 2012' for example.
    It should: http://uk.php.net/manual/en/datetime...s.relative.php

    'first day' ' of'? Sets the day of the first of the current month. This phrase is best used together with a month name following it. "first day of January 2008"
    Oddly though I was using this myself locally in a project with php 5.3.0 and when I uploaded to a server with php 5.2.7 it refused to work causing some minor annoyance. There is no mention of this in the php manual and the manual is normally very good at mentioning differences between versions.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I thought it did work as well, but when I hit up codepad it always returned 0. Couldn't find the docs for this in php, so I went straight for the gnu and it didn't have 'of' as a valid modifier in there (that I could find).
    Using just 'first x' was always working relative to week, so 'first friday' run today returns January 27th.

    So yes, 'OF' will definitely work, but not at codepad. Not sure what they've done differently; OF was valid in 5.2.17 (the only 5.2x version I have still), but they're version is 5.2.5.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Yes I noticed it wouldn't work on codepad too then I tried my main website and it didn't work there which was also on windows like my localhost and that was how i realised it was a version problem.

    Interesting that it works without 'of' though, that will make life a little easier
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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