fill in datatime field

1

I'm trying to fill in the input datetime-local but the field is blank, I already tried to send it in the format American and Brazilian but it does not come at all. in the database is stored in the American format: 2017-02-20 19:19:00 and in the html I try to insert like this:

<?php $date = new DateTime($situacao[0]['data_inicio']) ?>
<div class="form-group">
    <label for="txtDataInicio" class="col-sm-2 control-label">Data Inicio</label>
    <div class="col-sm-10">
        <input type="datetime-local" class="form-control" id="txtDataInicio" name="txtDataInicio" placeholder="Nome da Função" value="<?php echo (empty($situacao[0]['data_inicio']))? set_value('txtDataInicio'): $date->format('y-M-dh:m') ?>">
    </div>
</div>

In this line I've tried formatting in some formats, but without success.

    
asked by anonymous 25.03.2017 / 23:42

1 answer

1

If it's just to display the database in the input, you can directly display it without using DateTime

<?php $date = (!empty($situacao[0]['data_inicio'])) ? date('d/m/Y H:i:s', strtotime($situacao[0]['data_inicio'])) : set_value('txtDataInicio'); ?>
<div class="form-group">
    <label for="txtDataInicio" class="col-sm-2 control-label">Data Inicio</label>
    <div class="col-sm-10">
        <input type="datetime-local" class="form-control" id="txtDataInicio" name="txtDataInicio" placeholder="Nome da Função" value="<?php echo $date;?>">
    </div>
</div>

In this code it formats to the Brazilian standard dd / mm / YYYY H: i: s but you can use any pattern taking into account that it will be valid in function date()

    
26.03.2017 / 00:57