Finding Current Periode

I would like to select current academic year period based on current date.

Current date: 30 June 2014, the available academic year period was 1 July 2013 - 30 June 2014, but the return value ($last_id) was 0, it should be 1. The $current_date was not match with the if condition, the process went to die('stop@5…) which displayed ‘stop@5 0 2014-06-30=1404079200 2013-07-01=1372629600 2014-06-30=1404079200’

I don’t know why.

Here is my code:




public function getCurrentAcadYear(){

     $current_date=date("Y-m-d");

     $current_date_UNIX=strtotime(date('Y-m-d'));

     $LastRecord=$this->find(array('order'=>'id DESC'));

     

     if($LastRecord<>NULL){ //jika tidak kosong

          $last_id=$LastRecord->id;

          while ($last_id>0){

               $_begin=$LastRecord->begin;

               $_begin=date('Y-m-d', strtotime(str_replace(",", "", $_begin)));                    

               $_begin_UNIX=strtotime($_begin);                    

               $_end=$LastRecord->end;

               $_end=date('Y-m-d', strtotime(str_replace(",", "", $_end)));

               $_end_UNIX=strtotime($_end);                    

               if(($_begin_UNIX<=$current_date) and ($current_date<=$_end_UNIX)){

                        return $last_id;

               }

               else {

                     $last_id--;

                     $LastRecord=$this->findByPK(array('id'=>$last_id));

               }

          }

          die('stop@5 '.$last_id.' '.$current_date.'='.$current_date_UNIX.' '.$_begin.'='.$_begin_UNIX.'       '.$_end.'='.$_end_UNIX);

     }

     else{

          echo 'Tidak ada tahun akademik yg dapat dipilih';

     }

}