SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calculating 2nd week of the month

    Hi,

    I have searched through the php manual and the forums, however, I can't seem to figure out how to calculate weeks. ie... I need to make a script that shows a link on the 2nd week of each month, for duration of one week. Any ideas?

  2. #2
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like, in a calendar?
    ----------------
    bob.kennedy
    ----------------

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $timestamp time();

    $base date('M 1 Y');

    $start strtotime($base ' +1 weeks');

    $end strtotime($base ' +2 weeks');

    $show_link = ($timestamp >= $start && $timestamp $end);

    var_dump($show_link); 

  4. #4
    SitePoint Zealot whytewolf's Avatar
    Join Date
    Mar 2006
    Location
    montana
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well this works, if I'm understanding what you mean by second week {sunday through saterday}

    PHP Code:
    $week=time();
    $somepoint=mktime(0,0,0,date("m",$week),8,date("Y",$week));
    $startofsecondweek=mktime(0,0,0,date("m",$somepoint),8-date("w",$somepoint),date("Y",$somepoint));
    echo 
    date("r",$startofsecondweek); 

    this works because the 8th of the month is the only day thats always in the second week


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
  •