All the "date" in my database are of the following format: ‘d-m-Y’ (E.g. 09-03-2022)
I want have a field with input type=date, so user can modify the date.
I use the following code to pull data:
$date = "<input type="date" id="date" size= "50%;" name="date" value="$resJanuary 3, 2023" >";
...
<thead> <th>Date </th> <td>$date </td> </thead>
But my inputbox is showing dd/mm/yyyy instead of the actual date.
What formatting do I need to do to make my actual date show on the inputbox?
I have tried the following but doesn’t work:
$date = "<input type="date" id="date" size= "50%;" name="date" value="date('d-m-Y',$resJanuary 3, 2023)" >";
2
Answers
So I believe the reason why the date is not displaying on my input field is becuz it is in String datatype and need to format to DATE.
With this, I can also do the same for TIME
You are passing a wrong format to your date input.
Date input must fill with RFC3339 formatted text, you can read more about it.
To change your current format to
Y-m-d
format, you can use below code:If you are using MySQL, it uses
YYYY-MM-DD
format for date type column, so, saving the date withY-m-d
from PHP to MySQLdate
field seems to be the correct way.