我正在尝试将日期插入 mysql,但每次失败并在 phpmyadmin 中显示为 0000-00-00
I am trying to insert date into mysql but everytime it fails and comes out as 0000-00-00
in phpmyadmin
我的日期格式是 2012-08-06
(yyyy-mm-dd),数据库中的日期字段类型是 date
.
My date format is like 2012-08-06
(yyyy-mm-dd) and the date field type in database is date
.
$date = "2012-08-06";
mysql_query("INSERT INTO data_table (title, date_of_event)
VALUES('". $_POST['post_title'] ."',
'". $date ."')") or die(mysql_error());
尝试将 -
更改为 /
或删除它们,它不起作用.
tried changing -
to /
or removing them, it doesn't work.
在 MySQL 中尝试 CAST
函数:
try CAST
function in MySQL:
mysql_query("INSERT INTO data_table (title, date_of_event)
VALUES('". $_POST['post_title'] ."',
CAST('". $date ."' AS DATE))") or die(mysql_error());
这篇关于PHP - 将日期插入 mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!