您的位置:首页 > 数据库

SQL Server DATEDIFF() 函数

2012-05-28 12:18 155 查看

SQL Server DATEDIFF() 函数

定义和用法

DATEDIFF() 函数返回两个日期之间的天数。

语法

DATEDIFF(datepart,startdate,enddate)

startdate 和 enddate 参数是合法的日期表达式。

datepart 参数可以是下列的值:

datepart缩写
yy, yyyy
季度qq, q
mm, m
年中的日dy, y
dd, d
wk, ww
星期dw, w
小时hh
分钟mi, n
ss, s
毫秒ms
微妙mcs
纳秒ns

实例

例子 1

使用如下 SELECT 语句:

SELECT DATEDIFF(day,'2008-12-29','2008-12-30') AS DiffDate

结果:

DiffDate
1

例子 2

使用如下 SELECT 语句:

SELECT DATEDIFF(day,'2008-12-30','2008-12-29') AS DiffDate

结果:

DiffDate
-1
select datediff(ss,canceltime,bettime) '剩余投注时间(秒)' from lot_wagertick where type=1 and issue='2011844' and gaid in

(select gaid from lot_game where type=1 and status=1 and poscode='18757')

结果:

剩余投注时间(秒)

172740
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: