有没有办法格式化 mysql NOW() 所以我会得到类似年月日时分秒的东西,所有这些,像这样:
20130822143222
或者在 PHP 中获得类似 microtime() 的东西,但对于 MySQL?
我需要它作为插入前的触发器。谢谢 :)
SELECT DATE_FORMAT(NOW(),'%Y%m%d%H%i%s')
select date_format(NOW(),'%Y%m%d%H%i%s') as date_val
尝试:
DATE_FORMAT(NOW(),'%Y-%m-%d %h:%i:%s')
我认为这应该有效:
select UNIX_TIMESTAMP(NOW());
*约斯特
您可以使用字符串替换函数从输出中删除破折号、冒号和空格,NOW()
因为它只返回一个包含您想要的字符串,上面列出了用标点符号分隔的字符串。见http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
使用提取功能:
"Select EXTRACT(YEAR from NOW()) as year, EXTRACT(MONTH from NOW()) as month, EXTRACT(DAY
from NOW()) as day, EXTRACT(HOUR from NOW()) as hour, EXTRACT(MINUTE from NOW()) as
minute, EXTRACT(SECOND from NOW()) as second, EXTRACT(MICROSECOND from NOW()) as
microsecond, EXTRACT(MINUTE_MICROSECOND from NOW()) as minute_microsecond";
除此之外DATE_FORMAT
,这也应该起作用:SUBSTRING(NOW() + 0, 1, 8)
.