php - 更改PHP插入MySQL数据库的日期格式

标签 php mysql sql

我正在尝试以以下格式将当前日期插入 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/

相关文章:

php - include 和 header 函数不能在单个 php 文件中一起工作

php - 展开列以执行 SQL 搜索查询

PHP Mysql 从多个表中选择查询

php - 随机 MySQL 查询?或者随机化一个结果?

php - 变量的值未传递到 echo 语句中

mysql - ms sql数据库导入期间出现错误1064

php - 使用 XMLReader 在 PHP 中验证 SVG 文件

java - 当列表为 null 或为空时,JPA createQuery 将列表作为参数传递

mysql - 按字符串的某些部分排序

sql - 使用jdbc River将多个表从MySQL索引到elasticsearch