3

I want to replace data of HTML5 'datetime-local' field value with the 'MySQL datetime' value using PHP and JavaScript. But I tried many things it dint worked. Here is my code:

HTML Code:

Dispatch Date : <input type="datetime-local" id="dispatch_date" name="dispatch_date"/>

PHP and Javascript Code:

PHP:

$qry="select * from table_name ORDER BY p_rec_date DESC";
$result=mysql_query($qry);
$res = mysql_fetch_array($result)

$test_date2=date('d-m-Y g.i a', strtotime($res[9]));
$test_date=str_replace(" ", "_", $test_date2);

echo"<a id='".$res[0]."' href='javascript:void(0);' onclick=vpb_show_login_box(this.id,'".$test_date."');>".$res[0]."</a>";

JavaScript:

function vpb_show_login_box(id1,id2)
   {
      var replaced = id2.replace(/[_]/g,' ');
      document.getElementById("dispatch_date").value = replaced;
   }

1 Answer 1

1

As it says in the specification the date must be in RFC3339 format:

<?php
$qry="select * from table_name ORDER BY p_rec_date DESC";
$result=mysql_query($qry);
$res = mysql_fetch_array($result);
$date = date(DATE_RFC3339, strtotime($res[9]));
?><input type="datetime-local" value="<?php echo $date; ?>" />
Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't work in my case. The string I fetched from database is "2014-11-11T00:00:00+09:00".
What MySQL version was that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.