datepart | 缩写 |
---|---|
year |
yy, yyyy |
quarter |
qq, q |
month |
mm, m |
dayofyear |
dy, y |
day |
dd, d |
week |
wk, ww |
weekday |
dw |
hour |
hh |
minute |
mi, n |
second |
ss, s |
millisecond |
ms |
microsecond |
mcs |
nanosecond |
ns |
TZoffset |
tz |
以下实例:返回当前系统时间中年,月,日,dayofyear,星期等信息
SELECT DATENAME(year, getdate())
,DATENAME(month, getdate())
,DATENAME(day, getdate())
,DATENAME(dayofyear, getdate())
,DATENAME(weekday, getdate());
result为:2009 09 2 245 星期三
4.DATEPART
用法:datepart(datepart,date)作用同datename类似
从下例中可看出两者差别: datename返回的是字符串类型,datepart返回的是int类型
SELECT datepart(year, getdate())
,datepart(month, getdate())
,datepart(day, getdate())
,datepart(dayofyear, getdate())
,datepart(weekday, getdate());
result:2009 9 2 245 4