mysql 如何获取当前时间 前一小时的时间?
8 个解决方案
#1
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-08-08 13:59:30 |
+---------------------+
1 row in set (0.00 sec)
mysql> select date_sub(now(), interval 1 hour);
+----------------------------------+
| date_sub(now(), interval 1 hour) |
+----------------------------------+
| 2011-08-08 12:59:31 |
+----------------------------------+
1 row in set (0.00 sec)
#2
1喽正解
#3
select DATE_ADD(Now(),INTERVAL -1 hour);
select DATE_ADD(CURRENT_TIME(),INTERVAL -1 hour);
#4
正解+1
#5
where time < date_sub(NOW(),interval 60 minute);
#6
select now() - interval 1 hour;
#7
mysql> select now(),now() - interval 1 hour;
+---------------------+-------------------------+
| now() | now() - interval 1 hour |
+---------------------+-------------------------+
| 2011-08-08 14:32:11 | 2011-08-08 13:32:11 |
+---------------------+-------------------------+
1 row in set (0.11 sec)
mysql>
#8
这东西我怎么给忘了,回头用的时候还得查。
#1
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-08-08 13:59:30 |
+---------------------+
1 row in set (0.00 sec)
mysql> select date_sub(now(), interval 1 hour);
+----------------------------------+
| date_sub(now(), interval 1 hour) |
+----------------------------------+
| 2011-08-08 12:59:31 |
+----------------------------------+
1 row in set (0.00 sec)
#2
1喽正解
#3
select DATE_ADD(Now(),INTERVAL -1 hour);
select DATE_ADD(CURRENT_TIME(),INTERVAL -1 hour);
#4
正解+1
#5
where time < date_sub(NOW(),interval 60 minute);
#6
select now() - interval 1 hour;
#7
mysql> select now(),now() - interval 1 hour;
+---------------------+-------------------------+
| now() | now() - interval 1 hour |
+---------------------+-------------------------+
| 2011-08-08 14:32:11 | 2011-08-08 13:32:11 |
+---------------------+-------------------------+
1 row in set (0.11 sec)
mysql>
#8
这东西我怎么给忘了,回头用的时候还得查。