Let's suppose I have a record in database which has a start DateTime: 2016-03-10 00:00:00 and end DateTime 2016-03-10 06:00:00. Now each time i insert a new record in the database I want to check that the start DateTime & End DateTime are such that the duration never overlaps the previous records present in the Database. Is there any built-in function present in PHP CodeIgniter to check this?
Right now I am doing it using the following code but it doesn't work:
public function check_b_adds($data){
$sql='select * from listing_b_screen where (start_time >= ? AND end_time >= ?) OR (start_time <= ? AND end_time <= ?) OR (start_time <= ? AND end_time >= ?) OR (start_time = ? AND end_time = ?) OR (start_time >= ? AND end_time <= ?)';
$query=$this->db->query($sql, array($data['mystart_time'],$data['myend_time'],$data['mystart_time'],$data['myend_time'],$data['mystart_time'],$data['myend_time'],$data['mystart_time'],$data['myend_time'],$data['mystart_time'],$data['myend_time']));
$result = $query->result_array();
if ($result == NULL || $result == 0){
return false;
} else {
return True;
}
}