Put an input date

2

Friends, I have a normal input

<input type="datetime-local" class="form-control" id="fecha_y_hora_de_creacion">

and with ajax I bring the value of this input that is in a db and the server is like this:

2018-05-24 17:58:44

How do I load the value into the input if I can not do it this way?

$('#fecha_y_hora_de_creacion').val(res[0].fecha_y_hora_de_creacion);

the variable res [0] .date_and_hours_of_creation is the one that contains the value that comes from the DB and is 2018-05-24 17:58:44

Thanks for the little man.

    
asked by Mauricio Delgado 30.05.2018 в 00:42
source

1 answer

3

To set the correct value, you must separate date and time with a T like this:

$('#fecha_y_hora_de_creacion').val(res[0].fecha_y_hora_de_creacion.replace(' ', 'T'));
    
answered by 30.05.2018 в 00:48