我正在尝试以以下格式将当前日期插入 MySQL 数据库:(12/31/2013 10:26:12 PM)。我尝试编写一个简单的代码来更改格式,但得到的只是语法错误
$sql = "INSERT INTO Students
VALUES
('','" . $info[$i]['firstname'] . "', '" . $info[$i]['lastname'] . "',
'" . $info[$i]['sex'] . "', '" . $info[$i]['major'] . "',
'" . $info[$i]['favorite'] . "', '" . $info[$i]['GPA']
"TO_CHAR(SYSDATE(),'dd/mm/yyyy')";
请告诉我我该怎么处理它。
最佳答案
试试这个
$sql = "INSERT INTO Students VALUES ('','" . $info[$i]['firstname'] . "', '" . $info[$i]['lastname'] . "', '" . $info[$i]['sex'] . "', '" . $info[$i]['major'] . "', '" . $info[$i]['favorite'] . "', '" . $info[$i]['GPA'] . gmdate('m/d/Y g:i:s A').")";
或者试试这个
$sql = "INSERT INTO Students VALUES ('','" . $info[$i]['firstname'] . "', '" . $info[$i]['lastname'] . "', '" . $info[$i]['sex'] . "', '" . $info[$i]['major'] . "', '" . $info[$i]['favorite'] . "', '" . $info[$i]['GPA'] ."', '" . gmdate('m/d/Y g:i:s A').")";
您还可以将 gmdate 更改为日期 祝你有美好的一天
关于php - 更改PHP插入MySQL数据库的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17003951/