MySQL NOW() 只返回年份

标签 mysql datetime time

关于 NOW() 函数的 MySQL 文档...

Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

这是我的查询...

$sql = "

    INSERT INTO `users` ( `username`, `password`, `email`, `time` )
    VALUES ('{$username}', '" . sha1( $password ) . "', '{$email}', NOW() )

";

问题是在数据库中我没有完整的日期时间,只有年份。有什么解决办法吗?

最佳答案

It's int(10) like it was when I used UNIX timestamp.

NOW() 仅适用于 DATETIME 字段。

您需要将字段转换为 DATETIME(首选方法),或使用 UNIX_TIMESTAMP():NOW() 转换为 UNIX 时间戳

UNIX_TIMESTAMP(NOW())

关于MySQL NOW() 只返回年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5209864/

相关文章:

php - 在 Laravel 上合并具有值(value)的属性

Mysql - 从连接表返回最大值

php - 当我尝试运行使用 CodeIgniter 编写的项目时,出现 Xampp 未知错误

angularjs - Angular http 方法更改日期时间中的小时

python - 无法从一个日期时间列中减去另一列,减去操作不能使用类型为 dtype ('S1' ) 和 dtype ('<M8[ns]' ) 的操作数

c# - 获取特定区域的日期/时间?

ruby-on-rails - Ruby:计算2次之间的时间差

php - 需要使用 PHP 将 android 应用程序生成的纬度和经度值存储到 mySQL 数据库中

python - 检查列表中的任何时间是否在两个时间戳之间

java - 如何在 Java 中测量耗时?