I need to create a DateTime from the value received from a form. The problem is that the value is received like a string: "2016-10-10T08:29:06.959Z" and I need to received like 2016-10-10T08:29:06.959Z
without quotes, because if I receive with quotes I've got the next error:
DateTime::__construct(): Failed to parse time string ("2016-10-14T22:00:00.000Z") at position 0 ("): Unexpected character
When I try to transform the value to a DateTime with:
$fechaHasta = new DateTime($params["fechaHasta"]);
If I try to use:
$fecha2 = DateTime::createFromFormat("d-m-Y H:i:s", $data["fechaHasta"]);
I've got an empty object in $fecha2.
The form from where I send the data is:
<form id = "formSearch" class = "menu-table" method = "post" action = "<?php echo $this->basePath('/privado/actividades-planificadas/pai/exportdatatoexcel'); ?>">
<input type = "hidden" name = "codigoPPM" value = "{{searchForm.codigoPPM}}" />
<input type = "hidden" name = "fechaDesde" value = {{searchForm.dt1}} />
<input type = "hidden" name = "fechaHasta" value = {{searchForm.dt2}} />
<input type = "hidden" name = "estado" value = "{{searchForm.estadoSelected.id}}" />
<button type = "submit">
Exportar datos a Excel <img title = "Exportar tabla a Excel" src = "/img/logo-excel.png" />
</button>
</form>
So, what I have to do to send the value without quotes or transform the value received in DateTime.