-2

in my database table i have stored start_at and end_at timings of hotels


Here is my slim api php code

`  $st_time  = strtotime('Start_at');
  $end_time = strtotime('end_at');
  $stmt->execute();
  $data=$stmt->fetchAll( PDO::FETCH_ASSOC);
  $cur_time= time();
  if($st_time < $cur_time && $end_time > $cur_time)
  {
  echo $res='open ';
  }
 else
 {
 echo $res='Close';
 }

`

1 Answers1

0

You can do string comparisons and it will work in PHP. This is what will help you in the right direction...

  $st_time  = '07:30:00';
  $end_time = '22:30:00';
  $cur_time = date('H:i:s');
  if($st_time < $cur_time && $end_time > $cur_time){
    echo 'Open';
  } else {
    echo 'Close';
  }
Werner
  • 449
  • 4
  • 12