I’m new in codeigniter, im trying to create a function that accepts datetime input from a user. If the input is 2 or more days ahead of current datetime, it should return true, if not it should return false.
JavaScript
x
//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>
Advertisement
Answer
You could use DateTime() today +2 day
to get the next 2 days :
JavaScript
public function checkDateTimeInput(){
$dateTimeInput = new DateTime($this->input->post('dateTimeInput'));
$next_days = new DateTime('today +2 day');
if($dateTimeInput > $next_days) { /*Greater than 2 days or more*/
return true;
}else{
return false;
}
}