datename(datepart ,date) 返回表示指定日期的指定日期部分的字符串。
DATEPART ( datepart , date ) 返回代表指定日期的指定日期部分的整数。
DAY ( date ) 返回代表指定日期的天的日期部分的整数。
MONTH ( date )返回代表指定日期月份的整数。
YEAR ( date ) 返回表示指定日期中的年份的整数。
getdate() 返回当前的日期,返回类型为: datetime
DATEADD ( datepart , number, date )根据datepare ,使日期更加或减少number,
返回 datetime,但如果 date 参数是 smalldatetime,返回 smalldatetime。
number:
取一个整数值
是用来增加 datepart 的值。如果指定一个不是整数的值,则将废弃此值的小数部分。
例如: dateadd(mm,1,’2009-08-01’) 结果为datetime 类型的 2009-09-01 00:00:00.000
DATEDIFF ( datepart , startdate , enddate ) 返回跨两个指定日期的日期和时间边界数 返回类型为整数
startdate 是从 enddate 减去。如果 startdate 比 enddate 晚,返回负值。
datepart 可选项如下所示:
日期部分 | 缩写 |
---|---|
Year | yy, yyyy |
quarter | qq, q |
Month | mm, m |
dayofyear | dy, y |
Day | dd, d |
Week | wk, ww |
weekday | dw (dateadd,datediff 中的datepart不可使用此项) |
Hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |