Insert in the value of an input type="date" the date returned from the Select of the database

0

I'm getting a date from the database and displaying it in a input field in HTML.

However, for the client to be able to edit as a date, I need it to be in an input type="date". However, there seems to be some HTML5 restriction on this type of input.

How would I be able to insert this data into the input I want?

Example of my code:

 <input type="date" class="form-control" name="" id=""  value="<?=$data;?>" disabled >
    
asked by anonymous 09.05.2018 / 01:11

2 answers

2

Assuming the date on the bank is in the format YYYY-MM-DD hh: mm: ss

 //data retornada do banco
 $dataTime="2018-05-08 20:25:22";

 //parte válida da data para inserir no input type="date" YYYY-MM-DD
 $data = substr($dataTime,0,10); //2018-05-08

 <input type="date" class="form-control" name="" id="" value="<?=$data;?>" disabled >
  

In order to edit, you must remove this disabled

     
  • The substr returns a chunk of the string. For this, it uses three parameters: the string itself, the initial index and the amount of characters to be returned from the initial index.
  •   

Expected result:

 <input type="date" class="form-control" name="" id="" value="2018-05-08">
    
09.05.2018 / 01:32
1

The date must be in YYYY-MM-DD format.

Ex:

<input type="date" name="data" value="2013-12-01">
    
09.05.2018 / 01:17