Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

showing only week numbers after the 3rd of each month

i have an array of weeks:

$weeks = array('1','2','3','4' ... '52');

when it is the 3rd of each month, remove any week numbers previous to that current weeks week number.

for example:  todays date is the 09/04/2007 and the week number is 15.  since its gone past the 03/04/2007, my array should only contain week numbers 15 - 52.  if it was 02/04/2007, i would expect my array to contain weeks 14 - 52....

next week (week 16) my array should still contains week numbers 15 - 52. when it gets to 03/05/2007, my array should only contain week numbers from the 03/05/2007 to up week 52.  so this would be weeks 18 - 52 left... weeks 15, 16 & 17 would be removed as these weeks numbers come before the 3rd May 2007.

this is the code i was using but it isnt working.  after each week, the previous week number is been removed...  my idea was to get the current week number and store this in the array.  then i get the 3rd of the month and compare this against the current date.  if its before the 3rd of the month, show the previous week number up to week 52 etc etc

$weeks[] = date('W');

$the_3rd_of_the_month = '03/'.date('m').'/'.date('Y');

if(date('d/m/Y') < $the_3rd_of_the_month)
{
      $weeks[] = date('W')-1;
}

sort($weeks);

for($wk = $weeks[0]; $wk < 53; $wk++)
{
    // fill my select box
}
Avatar of adaoss
adaoss

Hi,
try this code:

<?php
      for ($i=0;$i<=52;$i++)
            $week[$i] = $i;

      $curWeek = date("W") - 1;

      for ($j = $curWeek; $j<=52;$j++) {
            // fill my select box
      }
?>

Hope this help,
Adão
ASKER CERTIFIED SOLUTION
Avatar of adaoss
adaoss

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

works perfect - thank you!