Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql datetime data to the html5 datetime-local field using javascript and PHP

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;
   }
like image 783
Prasad P.D. Avatar asked Apr 01 '26 17:04

Prasad P.D.


1 Answers

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; ?>" />
like image 75
akirk Avatar answered Apr 03 '26 07:04

akirk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!