save date and time field in sqlyog

mega-scorpion
mega-scorpion used Ask the Experts™
on
I want to save field in sqlyog , it's date datatype
I try the code below but it dosen't work

note : $today : field for date datatype
$today = date("m.d.y");
		$result = mysql_query( "INSERT INTO questionanswer (address,teacher_name,body,dateofsave) VALUES('$add','$tech_name','$bo','"$today"')", $link);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you should pass the value as format "yyyy-mm-dd"
try this,

$today = date("Y-m-d");
                $result = mysql_query( "INSERT INTO questionanswer (address,teacher_name,body,dateofsave) VALUES('$add','$tech_name','$bo','"$today"')", $link);

Open in new window

to work with date time,

you need to pass it as date,



$today = date("Y-m-d h:i:s");

Open in new window

Commented:
Your main problem is that you are using double quotes in a string contained within double quotes, the second problem as logudotcom says, the date format mysql server supports if your database is mysql is y-m-d, thus try this:
$today = date("Y-m-d");
                $result = mysql_query( "INSERT INTO questionanswer (address,teacher_name,body,dateofsave) VALUES('$add','$tech_name','$bo','".$today."')", $link);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial