Solved

showing only week numbers after the 3rd of each month

Posted on 2007-04-09
3
227 Views
Last Modified: 2007-04-09
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
}
0
Comment
Question by:ellandrd
  • 2
3 Comments
 
LVL 4

Expert Comment

by:adaoss
ID: 18875630
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
0
 
LVL 4

Accepted Solution

by:
adaoss earned 500 total points
ID: 18875670
Sorry last post, i forgot the 3rd day issue.

Here is the right answer:

<?php
      
      for ($i=0;$i<=52;$i++)
            $week[$i] = $i;
      
      $curDay = date("d");
      if ( $curDay < 3 ) {
            $curWeek = date("W") - 1;
      } else {
            $curWeek = date("W", mktime(0,0,0, date("m"), 3, date("Y")));
      }

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

Author Comment

by:ellandrd
ID: 18877017
works perfect - thank you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now