Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From MySQL to <input type="datetime-local">

Tags:

html

php

mysql

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.

like image 356
developers-have-no-vacation Avatar asked Nov 29 '22 07:11

developers-have-no-vacation


1 Answers

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

like image 80
didi67 Avatar answered Nov 30 '22 20:11

didi67