关于 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/