如何使用datepart从当前月份添加一个月 [英] how to add one month from the current month using datepart

查看:118
本文介绍了如何使用datepart从当前月份添加一个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用datepart从当前月份添加一个月



以上内容我写了如下查询





选择datepart(month,getdate())作为月份



当我执行输出时如下





7



它工作正常,假设当月是12月当我执行上面的查询



输出如下,



select datepart(month,getdate( ))作为月份





13



假设当月是十二月,并从当月添加一个月我希望输出如下,





如果当前月份是,我想要如下12月





1.





为什么我可以写sql查询。



Rgds,

Narasiman P.

解决方案

 选择 datepart(月,dateadd(月, 1 '  20131201')) as 


选择datepart(month,dateadd(month,1,getdate()))为[month] 


how to add one month from the current month using datepart

for the above thing i written the query as follows


select datepart(month,getdate()) as Month

when i execute the output as follows

Month
7

it is working correctly, suppose current month is December when i execute the above query

the output as follows,

select datepart(month,getdate()) as Month

Month
13

suppose current month is december,and add one month from the current month i want the output as follows,


Output i want as follows if current month is december

Month
1.


for that how can i write the sql query.

Rgds,
Narasiman P.

解决方案

select datepart(month,dateadd(month,1,'20131201') ) as Month


select datepart(month, dateadd(month, 1, getdate())) as [month]


这篇关于如何使用datepart从当前月份添加一个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆