Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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;
   }
share|improve this question

1 Answer 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; ?>" />
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.