天天看點

日期時間函數datediff、與celling

1、文法

      datediff(datepart,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

 celling(numeric_expression )  傳回大于或等于所給數字表達式的最小整數。

http://technet.microsoft.com/zh-cn/library/ee634541(v=sql.105).aspx celling用法

例:

select  tel,begindate,enddate,isnull(datediff(second,begindate,enddate),0)  as 按秒計時長, isnull(celling(convert(float,datediff(second,begindate,enddate),108)/60),0)  as 按分鐘計時長 from TelRecord

繼續閱讀