Jump to content

date is sent 0000.00.00 to mysql !


farahZ

Recommended Posts

hello, i'm sending date to mysql. when echoing the date in the browser, the date is correctly viewed.

$date=date("m.d.y");
echo $date;

 

but when sending to the database, its viewing there as 0's

is it a problem in the table in the db or the code itself

 

$sql = "INSERT INTO fooddiary (ID, Date, DayTime, FoodName, Calories)
VALUES ($clid, '$date', 'Breakfast', '$food', $cal)
ON DUPLICATE KEY UPDATE FoodName = '$food', Calories=$cal";
$result = mysqli_query($con, $sql) or die(mysqli_error());

other values are sent successfully!!
Link to comment
Share on other sites

Do NOT store dates as VARCHAR. You will not be able to use the mySql date functions, you will have problems with sorting and comparing, etc. etc.

 

Always store dates as DATE (or DATETIME or even TIMESTAMP). The server accepts and returns them as YYYY-MM-DD. You can change the way it displays when you retrieve the data.

 

Would you store numbers as "two hundred fifty-seven and 23/100" just so you can print it on a check? Of course not.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.