SQL Question

I want to update DATE field(type: date),Can anyone point out the way to do that,

I tried getdate() function, made a string and converted to date and did an update quary but won't work.(im new to php)

$date = getdate();
$mydate = $date['mon']."/".$date['mday']."/".$date['year'];
$time = strtotime('$mydate');
$newformat = date('Y-d-m');
$sql = "UPDATE product SET p_date =".$newformat. "WHERE p_id = 2";


won't update, may be the query wrong, i just want to update table with the sysem date date

Answer Source

Like you said in php this is the format

Correct format for a MySQL DATETIME column is
<?php $mysqltime = date ("Y-m-d H:i:s", $phptime); ?>

Try this

$date = date('Y-m-d H:i:s'); 
mysql_query("INSERT INTO table (datePosted) VALUES ('$date')");

Take a look at the manual.Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download