I have a database field (mysql database , of the datetime type) , and it's being filled by PHP. In my html I use an input with the datetime-local type.
From the form , 2014-04-18T18:30
is passed to the mysql database, which stores it as 2014-04-18 18:30:00
.
The thing is : now I want to retrieve said data (to edit the date in my CMS) , and put it as a value into the input field. The issue is that it has to be the old format, not the format mysql converted it to. I can obviously write my own function to take care of it but I'd like to know if there is a default way in php to get it done. Is there an RFC format allowing me to do something like this :
<?php
$database-date = "2014-04-18 18:30:00"; // this would be retrieved from mysql
$newdate = date(DATE_RFC3339, strtotime($database-date)); // convert it ?
echo $newdate; // I would obviously echo this inside the value of my input
?>
Any help is appreciated.
I had the same problem and I solved it by simply putting that in the value field :
value = date("Y-m-d\TH:i:s", strtotime($yourdate))
No need ATOM or W3C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With