Date question figuring out a period

Hi
I am currently collecting dates as 1-1-2008, 10-1-2008 and such format
1-1-2008
m-d-yyyy

Now I am trying to figure this out

I need to make three periods of time.
Period1
period 1 will contain anything from month january to april
period2 will contain anything from month may till august
Period3 will contain anything from month september till december

so lets say a record has a date of 10-1-2008 it should fall under the timeperiod Period3
so my timeperiod firld should say Period3 in it.
How could I do that?
Thanks
LVL 9
syedasimmeesaqAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
Split the date up and compare it like so

(UNTESTED)

$dt = explode( "-", $yourDateField);

switch( $dt[0] ) {

     case 1:
     case 2:
     case 3:
     case 4: $period = "Jan to April";
                 break;

     case 1:
     case 2:
     case 3:
     case 4: $period = "Jan to April";
                 break;

     case 5:
     case 6:
     case 7:
     case 8: $period = "May to Aug";
                 break;

     case 9:
     case 10:
     case 11:
     case 12: $period = "Sep to Dec";
                 break;

}
0
Beverley PortlockCommented:
Oops - just noticed that part of the cases are repeated. Should be as below

$dt = explode( "-", $yourDateField);

switch( $dt[0] ) {

     case 1:
     case 2:
     case 3:
     case 4: $period = "Jan to April";
                 break;

     case 5:
     case 6:
     case 7:
     case 8: $period = "May to Aug";
                 break;

     case 9:
     case 10:
     case 11:
     case 12: $period = "Sep to Dec";
                 break;

}


An additional point is that you could do it

if ( $dt[0] >= 1 && $dt[0] <= 4 )
     $period = "period 1";
else
     if ( $dt[0] >= 5 && $dt[0] <= 8 )
         $period = "period 2";
     else
           if ( $dt[0] >= 9 && $dt[0] <= 12 )
                $period = "period 3";

but I feel that the use of the SWITCH gives clearer code that is easier to modify later.
     
0
syedasimmeesaqAuthor Commented:
sorry to reply so late but I got busy

This is what I think I want to do. Lets say today is Nov 19th, 2008. if the scrip can look for the current date and then echo out what period would it be

If its between Jan and April then its Springs
if its between May and August then its Fall
if its Sep and Dec then its Winters

any idea. Thanks
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Beverley PortlockCommented:
Well, since only only need the month we could mod it like so


$month = date("m");

switch( $month ) {

     case 1:
     case 2:
     case 3:
     case 4: $period = "Spring";
                 break;

     case 5:
     case 6:
     case 7:
     case 8: $period = "Fall";
                 break;

     case 9:
     case 10:
     case 11:
     case 12: $period = "Winter";
                 break;

}

echo "The period is $period";
0
syedasimmeesaqAuthor Commented:
well I found out I could do this

$my_t=getdate(date("U"));

print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]<br>");
$myYear = $my_t[year];
if ($my_t[mon] <= 2 ) { $season =  "Winter"; }// then you have spring
if ($my_t[mon] >= 3 and $my_t[mon] <= 6)  { $season =  "Spring"; }// then you have fall
if ($my_t[mon] >= 9 and $my_t[mon] <= 11){$season =  "Fall"; }
if ($my_t[mon]  = 12) { $season =  "Winter"; }
// then you have winter
echo $my_t[mon];

but only problem is that its November but when I echo $my_t[mon]; it shows me 12

whys that, do you know thanks
0
Beverley PortlockCommented:
The reason it shows 12 is because you are setting it to 12 in this

if ($my_t[mon]  = 12) { $season =  "Winter"; }

which should be

if ($my_t[mon]  == 12) { $season =  "Winter"; }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.