title: mysql datetime data to the html5 datetime-local field using javascript and PHP
body: <p>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: </p>
  
  <p><strong>HTML Code:</strong></p>
  
  <pre><code>Dispatch Date : &lt;input type="datetime-local" id="dispatch_date" name="dispatch_date"/&gt;
  </code></pre>
  
  <p><strong>PHP and Javascript Code:</strong></p>
  
  <p>PHP:</p>
  
  <pre><code>$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"&lt;a id='".$res[0]."' href='javascript:void(0);' onclick=vpb_show_login_box(this.id,'".$test_date."');&gt;".$res[0]."&lt;/a&gt;";
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>function vpb_show_login_box(id1,id2)
     {
        var replaced = id2.replace(/[_]/g,' ');
        document.getElementById("dispatch_date").value = replaced;
     }
  </code></pre>