Results 1 to 2 of 2

Thread: Semester using months results

  1. #1
    Join Date
    Jun 2007
    Location
    DeKalb, IL
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Semester using months results

    You would think it would be simple
    So then why doesn't this work?

    I've tried these two:

    Code:
    $currentMonth = date("m");
    $semester = "";
    if ($currentMonth >= 01 && $currentMonth <= 05) {
    	$semester = "Spring";
    } elseif ($currentMonth >= 06 && $currentMonth <= 08) {
    	$semester = "Summer";
    } else {
    	$semester = "Winter"; }
    Code:
    $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?

  2. #2
    Join Date
    Jun 2007
    Location
    DeKalb, IL
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Possible solution?

    My brother told me use a switch:

    Code:
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •