dongli564510 2016-03-06 21:31
浏览 79
已采纳

PHP CodeIgniter中的持续时间重叠检查

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;
    }
}
  • 写回答

2条回答 默认 最新

  • duanniling0018 2016-07-07 11:29
    关注
        $fromdaysDate="2016-07-13";//changed date
        $todaysDate="2016-07-25";//changed date
        $this->db->select('task_id,task_start_date, task_due_date'); 
        $this->db->where('task_start_date <="'.date('Y-m-d', strtotime($fromdaysDate)).'"');
        $this->db->where('task_due_date >="'.date('Y-m-d', strtotime($todaysDate)).'"');    
        $this->db->or_where('task_due_date BETWEEN "'. date('Y-m-d', strtotime($fromdaysDate)). '" and "'. date('Y-m-d', strtotime($todaysDate)).'"');   
        $alltask=$this->db->get('wba_task')->result_array();
        echo $this->db->last_query();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?