jeudi 26 novembre 2015

How to show records that falls on the date-range using if statement (php)?

I want to display all the records during August of the current year up to December of the current year. While it will not display on January up to June, Instead the Records of January up to June will be displayed. How will I catch the date using IF statement?

Here is my code:

            $year = date("Y");
            $sem1_start = date("M-d-Y", strtotime("August, 01".$year));
            $sem1_end = date("M-d-Y", strtotime("December, 31".$year));

            $sem2_start = date("M-d-Y", strtotime("January, 01".$year));
            $sem2_end = date("M-d-Y", strtotime("June, 15".$year));

            //sample date from database
            $date = '2015-10-15';
            $date2 = date("M-d-Y", strtotime($date));


            if($date2 >= $sem1_s && $date2 <= $sem1_e){
                //Display all records
            }
            else if($date2 >= $sem2_s && $date2 <= $sem2_e){
                 //Display all records
            }

I wanted to automatically display the records of the current semester (August-December) and when January comes, it will hide the records but will display the records of the second semester which is January up to June.

Thank you!!!

Aucun commentaire:

Enregistrer un commentaire