Web Analytics Made Easy -
StatCounter display all weeks between any two dates - CodingForum

Announcement

Collapse
No announcement yet.

display all weeks between any two dates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • display all weeks between any two dates

    hi,
    i want to display all weeks falling between any two dates in php. Can some one help me on this??

    Thanks

  • #2
    here's a quick code i threw together to find weeks between any 2 selected dates
    PHP Code:
    <?php
    if(empty($_POST['start_month'])){
    echo 
    "<form action='' method='post'><center>
    START DATE: <select name='start_month'>
    <option value='0' selected>Month</option>
    <option value='1'>Jan</option>
    <option value='2'>Feb</option>
    <option value='3'>Mar</option>
    <option value='4'>Apr</option>
    <option value='5'>May</option>
    <option value='6'>Jun</option>
    <option value='7'>Jul</option>
    <option value='8'>Aug</option>
    <option value='9'>Sep</option>
    <option value='10'>Oct</option>
    <option value='11'>Nov</option>
    <option value='12'>Dec</option>
    </select>
    <select name='start_day'>
    <option value='0' selected>Day</option>"
    ;
    for(
    $i=1;$i<=31;$i++){
    echo 
    "<option value='$i'>$i</option>\n";
    }
    echo 
    "</select><input type='text' size='5' name='start_year' value='YEAR'><hr>END DATE: ";
    echo 
    "<select name='end_month'>
    <option value='0' selected>Month</option>
    <option value='1'>Jan</option>
    <option value='2'>Feb</option>
    <option value='3'>Mar</option>
    <option value='4'>Apr</option>
    <option value='5'>May</option>
    <option value='6'>Jun</option>
    <option value='7'>Jul</option>
    <option value='8'>Aug</option>
    <option value='9'>Sep</option>
    <option value='10'>Oct</option>
    <option value='11'>Nov</option>
    <option value='12'>Dec</option>
    </select>
    <select name='end_day'>
    <option value='0' selected>Day</option>"
    ;
    for(
    $i=1;$i<=31;$i++){
    echo 
    "<option value='$i'>$i</option>\n";
    }
    echo 
    "</select><input type='text' size='5' name='end_year' value='YEAR'><hr>";
    echo 
    "<input type='submit' value='Find the days >>'></center>
    </form>"
    ;
    }else{
    $start_date mktime(0,0,0,$_POST['start_month'],$_POST['start_day'],$_POST['start_year']);
    $end_date mktime(0,0,0,$_POST['end_month'],$_POST['end_day'],$_POST['end_year']);
    $time_between $end_date-$start_date;
    //find the days
    $day_count ceil($time_between/24/60/60);
    //find the names/dates of the days
    for($i=0;$i<=$day_count;$i++){
        if(
    $i==&& date("l",$newtime) != "Sunday"){
        
    //we're starting in the middle of a week.... show 1 earlier week than the code that follows
        
    for($s=1;$s<=6;$s++){
        
    $newtime $start_date-($s*60*60*24);
        if(
    date("l",$newtime) == "Sunday"){
        
    $end_of_week $newtime+(6*60*60*24);
        echo 
    date("F jS, Y",$newtime)." through ".date("F jS, Y",$end_of_week)." is a week.<br />";
        }
        }
        }else{
        
    $newtime $start_date+($i*60*60*24);
        if(
    date("l",$newtime) == "Sunday"){
        
    //Beginning of a week... show it
        
    $end_of_week $newtime+(6*60*60*24);
        echo 
    date("F jS, Y",$newtime)." through ".date("F jS, Y",$end_of_week)." is a week.<br />";
        }
        }
    }
    }
    ?>
    Last edited by boeing747fp; Oct 14, 2006, 12:02 PM.

    Comment


    • #3
      Million Thanks!!!

      hi ,
      Thanks a lot for the valueable code.its of a great help to me.

      Bhakti Thakkar

      Comment

      Working...
      X