SQL時間相關 - SQL日期,時間比較

SQL Server 中時間比較
mysql

例子:
sql

select count(*) from table where DATEDIFF ([second], '2004-09-18 00:00:18', '2004-09-18 00:00:19')  > 0spa

說明table

  select  DATEDIFF(day, time1 , time2)    對應示例語句以下
select

  select  DATEDIFF(day, '2010-07-23 0:41:18', '2010-07-23 23:41:18')im

  time1 > time2 爲負數;filter

  time1 < time2 爲正數;tab

  [day] :只會比較 2010-07-23 忽略 0:41:18' 其餘同理時間

如下分別: 
co

 

  年: 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) 

相關文章
相關標籤/搜索