如何检查我选择的日期和时间是否在持续时间内(是分钟数)?
这是我的代码:
function checkTimeDate(){
$time = $this->input->post("time", true);
$this->db->select("time, duration");
$this->db->from("timetable");
$query = $this->db->get();
$message = array();
$timeConverted = strtotime($time);
foreach($query->result() as $row){
if($timeConverted == $row->time){
$message = array(
"message" => "Please pick another date and time"
);
}else{
$message = array(
"message" => "Available"
);
}
}
$this->output->set_output(json_encode($message));
}
在那个逻辑中,我只是检查所选时间和日期是否等于我的数据库中的值。我想添加持续时间。提前致谢。
答案 0 :(得分:0)
我相信你正在寻找这样的东西:
if $timeConverted >= $row->time && $timeConverted <= $ row->time + $row->duration
答案 1 :(得分:0)
试试这个
$this->db->select("*");
$this->db->from("tbl_name");
$this->db->where("now() >= DATE_SUB(selected_date,INTERVAL 30 DAY)");