Pass a string with Datetime format to PHP time

2

I want to pass the content I have in an input with% co_from% to time, I tried it with strtotime but it does not give me the expected result.

$fecha = strtotime($this->input->post("fecha")); 

It returns "0" when I want it to return the time of the indicated date.

    
asked by Jesús 14.06.2016 в 11:18
source

1 answer

2

Try passing the date to this format: yyyy-mm-dd hh: mm: ss before using the strtotime The example code:

$fechaFormateada = formatearFecha($this->input->post("fecha"));
$fecha = strtotime($fechaFormateada); 

function formatearFecha($fecha)
{
$fechaSeparada = explode(" ", $fecha);
$partesFecha = explode("/", $fechaSeparada[0]);
$nuevaFecha = $partesFecha[2] . "-" . $partesFecha[1] . "-" $partesFecha[0] . " " . $fechaSeparada[1];

return $nuevaFecha;
}
    
answered by 14.06.2016 в 11:34