Display date of MySQL in date field

2

I have a customer registration page with a field for date of birth. I can choose a date and save it in the database. But when I go back to that client's signup screen this field ( type="date" ) is not displaying the value saved in the database. Can anyone help me understand what's wrong with my code?

<? $dtnascimento = '';
if($rst[0]['datanascimento'] != '') {
   $dtnascimento = $rst[0]['datanascimento'];
   $dtnascimento = date_format(date_create($dtnascimento),"d/m/Y");
} ?>

<label>Data de Nascimento</label>
<input type="date" id="datansc" name="datansc" value="<? echo $dtnascimento ;?>"/>
    
asked by anonymous 06.09.2017 / 20:50

2 answers

3

Try formatting the date for YYYY-MM-DD .

This is the format supported by HTML5.

If you really need to modify or mask the date try to view this topic: link

<div>
Note que ele despreza a data:
<input type="date" id="datansc" name="datansc" value="15/02/1975"/>
</div>

<div>
Note que agora ele exibe o valor:
<input type="date" id="datansc" name="datansc" value="1975-02-15"/>
</div>
    
06.09.2017 / 21:09
0

What you need to use is this here:

<?= date_format(new DateTime($dtnascimento),'d/m/Y') ?>

<?= date_format(new DateTime($dtnascimento),'d/m/Y H:i:s') ?>
    
07.09.2017 / 14:38