Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中创建一个函数,如果输入日期时间比当前日期时间早2天,则返回true,否则返回false_Php_Codeigniter - Fatal编程技术网

Php 在codeigniter中创建一个函数,如果输入日期时间比当前日期时间早2天,则返回true,否则返回false

Php 在codeigniter中创建一个函数,如果输入日期时间比当前日期时间早2天,则返回true,否则返回false,php,codeigniter,Php,Codeigniter,我是codeigniter的新手,我正在尝试创建一个接受用户日期时间输入的函数。如果输入比当前日期时间提前2天或更长时间,则应返回true,否则应返回false //my controller looks like this: public function checkDateTimeInput(){ $dateTimeInput = $this->input->post('dateTimeInput'); if($dateTimeInput /*Gr

我是codeigniter的新手,我正在尝试创建一个接受用户日期时间输入的函数。如果输入比当前日期时间提前2天或更长时间,则应返回true,否则应返回false

//my controller looks like this:
public function checkDateTimeInput(){
        $dateTimeInput = $this->input->post('dateTimeInput');
        if($dateTimeInput /*Greater than 2 days or more*/){
            return true;
        }else{
            return false;
        }
    }



//in my view:
<?php echo form_open('schedules/checkDateTimeInput'); ?>
    <input type="datetime-local" name="dateTimeInput">
    <input type="submit" value="submit">
</form>
//我的控制器如下所示:
公共函数checkDateTimeInput(){
$dateTimeInput=$this->input->post('dateTimeInput');
如果($dateTimeInput/*大于2天或更长时间*/){
返回true;
}否则{
返回false;
}
}
//我认为:
您可以使用
今天+2天
获得接下来的2天:

公共函数checkDateTimeInput(){
$dateTimeInput=newdatetime($this->input->post('dateTimeInput');
$next_days=新日期时间(“今天+2天”);
如果($dateTimeInput>$next_days){/*大于2天或更长时间*/
返回true;
}否则{
返回false;
}
}

您应该在控制器中尝试此操作,下面给出的代码适用于12小时格式

//my controller looks like this:
public function checkDateTimeInput() {
    // date_default_timezone_set("Asia/Kolkata"); // make sure you have set it to yours in config file
    $date1 =  date('Y-m-d h:i:sa', strtotime('+2 days'));
    $posted_date_time = date('Y-m-d h:i:sa', strtotime($this->input->post('dateTimeInput')));

    if($posted_date_time >= $date1){
        //return true;
        echo "True";
    }
    else {
        //return false;
        echo "False";
    }
}

不管怎样,谢谢你的主意,我现在已经开始工作了。而不是:$next_days=new DateTime('now+2天');我用的是:$next_days=date('Y-m-d',strottime(+2天));我已经更新了我的答案,应该先格式化发布日期,然后改为使用
today
参数