PDA

View Full Version : Semester using months results



lindsaycb
07-31-2008, 07:56 PM
You would think it would be simple
So then why doesn't this work?

I've tried these two:


$currentMonth = date("m");
$semester = "";
if ($currentMonth >= 01 && $currentMonth <= 05) {
$semester = "Spring";
} elseif ($currentMonth >= 06 && $currentMonth <= 08) {
$semester = "Summer";
} else {
$semester = "Winter"; }


$currentMonth = date("m");
$semester = "0";
if ($currentMonth > 00 && $currentMonth < 06) {
$semester = "Spring";
} elseif ($currentMonth > 05 && $currentMonth < 09) {
$semester = "Summer";
} else {
$semester = "Winter"; }

It will give me either Winter using the && operator and Spring if I use the ||. But neither will give me Summer, which is what it should be since it's 07.

What do you think? Is it possible to get this to work?

lindsaycb
07-31-2008, 08:22 PM
My brother told me use a switch:


switch ($currentMonth) {
case 01:
case 02:
case 03:
case 04:
case 05:
$semester = "Spring";
break;
case 06:
case 07:
case 08:
$semester = "Summer";
break;
case 09:
case 10:
case 11:
case 12:
$semester = "Winter";
break;
}

It works but I don't understand why a, if/else statement couldn't do the job.