我正在尝试通过在表中组合日期和时间字段来从查询中检索UNIX时间戳,但它会一直返回为零。
SELECT *,
UNIX_TIMESTAMP(startdate starttime) AS start,
UNIX_TIMESTAMP(enddate endtime) AS end
FROM mytable;
任何人都可以帮助我吗?
感谢。
答案 0 :(得分:4)
未经测试但应该有效:
SELECT UNIX_TIMESTAMP(CONCAT(startdate, ' ', starttime)) AS start;
答案 1 :(得分:1)
看看这个:
mysql> select TIMESTAMP(curdate(), curtime()), TIMESTAMP(curdate(), curtime()) + 0;
+---------------------------------+-------------------------------------+
| TIMESTAMP(curdate(), curtime()) | TIMESTAMP(curdate(), curtime()) + 0 |
+---------------------------------+-------------------------------------+
| 2010-04-21 19:03:23 | 20100421190323 |
+---------------------------------+-------------------------------------+
1 row in set (0.00 sec)
对不起,还有一些补充:
mysql> select UNIX_TIMESTAMP(TIMESTAMP(curdate(), curtime())), UNIX_TIMESTAMP();
+-------------------------------------------------+------------------+
| UNIX_TIMESTAMP(TIMESTAMP(curdate(), curtime())) | UNIX_TIMESTAMP() |
+-------------------------------------------------+------------------+
| 1271862564 | 1271862564 |
+-------------------------------------------------+------------------+
1 row in set (0.00 sec)