日期增减函数可以对日期指定部分的值进行增减,并返回处理后的日期值。
具体语法:DATEADD(deapart,number,date)
depart:是规定应该向日期的哪一部分返回新值的参数
DATEADD、DATEDIFF支持的日期部分、缩写及含义
日期部分 |
缩写 |
含义 |
Year |
yy |
年份 |
Quarter |
qq |
季度 |
Month |
mm |
月份 |
Dayofyear |
dy |
日 |
Day |
dd |
|
Week |
wk |
星期 |
Hour |
Hh |
小时 |
Minute |
mi |
分钟 |
Second |
ss |
秒 |
Millisecond |
Ms |
毫秒 |
number:是用来增加depart的值。正数表示增加,负数表示减少。如果指定的是非整数值,则忽略此值的小数部分,不做四舍无入。如:DATEADD(dd,1.7,date)表示date增加1天。
date:是返回datetime或smalldatetime值或日期格式字符串的表达式
注意事项:当date为datetime,depart为Ms时,返回值将根据日期增减函数的结果调整为3/%秒;当date为smalldatetime,depart为ss或Ms时,返回值将根据日期增减函数的结果。date允许直接与number进行增减计算,即:DATEADD(dd,number,date)等价于date+number。
示例
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)