SQL時間相關
SQL
Server 中時間比較
例子:
select count(*) from table where DATEDIFF ([second], '2004-09-18 00:00:18', '2004-09-18 00:00:19') > 0
說明
select
DATEDIFF(day, time1 , time2) 對應示例語句如下
select DATEDIFF(day, '2010-07-23 0:41:18', '2010-07-23 23:41:18')
time1 > time2 為負數;
time1 < time2 為正數;
[day]
:只會比較 2010-07-23
以下分別:
年: SELECT DATEDIFF([year],time1 , time2) 返回值: -6 ,說明是後減前 與 mysql 相反的。
月: SELECT DATEDIFF([month], time1 , time2)
天: SELECT DATEDIFF([day], time1 , time2)
小時: SELECT DATEDIFF([hour], time1 , time2)
秒: SELECT DATEDIFF([second], time1 , time2)