I get the following error, I'm trying to do a range filter by dates, I'm using CodeIgniter 3x
, I send the following dates by AJAX
to PHP
:
$fecha1 = 21/07/2017;
$fecha2 = 21/07/2017;
In this way I separate the date from the example field: 21/07/2017 - 22/07/2017
, so I read is that by making the split
remains as a string
, how would I have to convert it to date
?
JS
:
var str = value.split("-");
var rango1= $.trim(str[0]);
var rango2= $.trim(str[1]);
var ParamObjSend={
'fecha_rango1' : rango1,
'fecha_rango2' : rango2,
}
Verify that the data correctly arrives at PHP
.
The error marks me on the line:
$fecha_reserva1 = new DateTime($fecha1);
Message: DateTime :: __ construct (): Failed to parse time string (07/21/2017) at position 0 (2): Unexpected character
public function RangoFecha(){
$fecha1 =$this->input->post('fecha_rango1');
$fecha2 =$this->input->post('fecha_rango2');
$fecha_reserva1 =new DateTime($fecha1);
$fecha_reserva2 =new DateTime($fecha2);
$Where['agenda.fecha_reserva>='] =date_format($fecha_reserva1,'Y-m-d');
$Where['agenda.fecha_reserva<='] =date_format($fecha_reserva2,'Y-m-d');
$Where['agenda.tipo']='Cita';
$resultado = $this->Model->ListarAgenda($Where);
}