如何查找从当年到上一年的月份,这意味着总月数应为12个月。 [英] How to find month from current year to previous year which means total month count should 12 months.
本文介绍了如何查找从当年到上一年的月份,这意味着总月数应为12个月。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想知道sql server中的以下日期格式
如何查找当前年份到上一年的月份,这意味着总月数应为12几个月。
预期产量:
输入:2016-04-26
输出:2015-03-26 //这是输出
请给我一个解决方案。
提前感谢。
我尝试过:
如何查找当前年份到上一年的月份,这意味着总月份数应为12个月。
Hi all,
I want to know the below date format in sql server
how to find month from current year to previous year which means total month count should 12 months.
Expected output:
input : 2016-04-26
output: 2015-03-26 // this is for output
please drop me a solution for this.
thanks in advance.
What I have tried:
how to find month from current year to previous year which means total month count should 12 months.
推荐答案
declare @date date
set @date = getdate()
select DATEADD(MONTH,-12,@date)
你好,
使用DATEADD函数获取所需的OP。
链接: DATEADD(Transact-SQL)
Hello ,
Use DATEADD function to get required OP .
Link :DATEADD (Transact-SQL)
select DATEADD(MONTH,-13,getdate())
将给出
will give
dt
2015-03-26 15:55:43.560
这篇关于如何查找从当年到上一年的月份,这意味着总月数应为12个月。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文