Reputation: 79
Pretty simple to some people, but pretty new to PHP. I just want to insert today date into a date field in MySQL
Thanks in advance.
$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='date('Y-m-d')' WHERE Reference='$Reference'";
$result=mysql_query($sql);
Upvotes: 2
Views: 87
Reputation: 767
You can also use:
$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate=now() WHERE Reference='$Reference'"; $result=mysql_query($sql);
This will work both: when IASubmittedDate is date or IASubmittedDate is datetime
Upvotes: 0
Reputation: 81
I think the simplest answer is as follows:
$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='". date('Y-m-d'). "' WHERE Reference='$Reference'";
$result=mysql_query($sql);
Upvotes: 4
Reputation: 3275
You can simply do this without the php date()
function by using MySQLs CURDATE()
function. This should look like this
$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate=CURDATE() WHERE Reference='$Reference'";
$result=mysql_query($sql);
Upvotes: 0
Reputation: 11556
Try this
sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='" DATE_FORMAT(NOW(),'%Y-%m-%d') "' WHERE Reference='$Reference'";
$result=mysql_query($sql);
Upvotes: 0
Reputation: 231
try this :
$date = date('Y-m-d');
sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='". $date. "' WHERE Reference='$Reference'";
$result=mysql_query($sql);
hope this can help you.
Upvotes: 0