码迷,mamicode.com
首页 > 数据库 > 详细

SQL时间相关 - SQL日期,时间比较

时间:2014-10-09 00:14:57      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:ar   strong   sp   c   on   r   时间   ef   bs   

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 忽略 0:41:18‘ 其他同理

以下分别: 

 

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

SQL时间相关 - SQL日期,时间比较

标签:ar   strong   sp   c   on   r   时间   ef   bs   

原文地址:http://www.cnblogs.com/soundcode/p/4011391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!