Reputation: 31
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;
}
Upvotes: 3
Views: 2111
Reputation: 6857
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; ?>" />
Upvotes: 1