...

View Full Version : How do I insert current date into mySQL?



ozlad
05-03-2006, 12:03 AM
I have a table, new, with fields id, member, datein, dateout

Can anyone tell me why this won't work

if ($submit) {
$sql = "INSERT INTO new VALUES('','$member','curdate()','date_add(now(), interval 1 year)')";
$result = mysql_query($sql);
if ($result) {
echo "Done";
exit();
}
}

yet this does work

if ($submit) {
$sql = "INSERT INTO new VALUES('','$member','','')";
$result = mysql_query($sql);
if ($result) {
$sql = "UPDATE new SET datein=curdate(), dateout=date_add(now(), interval 1 year) WHERE member='$member'";
$result = mysql_query($sql);
echo "Done";
exit();
}
}

Any help appreciated

GJay
05-03-2006, 12:11 AM
because cur_date and date_add are 'functions', I don't think they should be in the single-quotes, as that will mean they get treated as strings- not a valid date-time format.

ozlad
05-03-2006, 12:48 AM
Thanks so much GJay, that is the answer

I had been looking at it for too long I think :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum