I don’t know if that will work for you, but based on what you said, [color=#880000][size=2]//I added $i condition to avoid infinite loop[/size][/color]
I have a similar problem with my code, The if condition is ‘true’ while $current_date greater than $__begin and $current_date smaller than $_end, but always false when $current_date equal to $__begin or equal to $__end.
Is there any wrong syntax?
Here is the code:
public function getCurrentAcadYear(){
$current_date=new DateTime();
$LastRecord=$this->find(array('order'=>'id DESC'));
if($LastRecord){ //jika tidak kosong
$last_id=$LastRecord->id;
while ($last_id){
$begin=$LastRecord->begin;
$_begin=date('Y-m-d', strtotime(str_replace(",", "", $begin)));
$__begin = new DateTime($_begin);
$end=$LastRecord->end;
$_end=date('Y-m-d', strtotime(str_replace(",", "", $end)));
$__end = new DateTime($_end);
if(($current_date>=$__begin) AND ($current_date<=$__end))
return $last_id;
else {
$last_id--;
$LastRecord=$this->findByPK(array('id'=>$last_id));
}
}
}
else
echo 'Tidak ada tahun akademik yg dapat dipilih';
}