如何在Sql Server中找到天数? [英] How to find Number of Days in Sql Server?
本文介绍了如何在Sql Server中找到天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在特定日期找到Sql Server中的天数
例如
声明@date datetime ='''2012-11-25''
我必须找到No. @date的天数(即)11月份的天数
我的答案应该是30
解决方案
尝试以下代码: -
SELECT DATEPART(日,DATEADD (s,-1,DATEADD(mm,DATEDIFF(m, 0 ,' 2011-02-25')+ 1, 0 )))
尝试以下一个并通过你需要的月份
SELECT DATEPART(dd,DATEADD(s,-1,DATEADD(mm,DATEDIFF(m, 0,GETDATE())+ 1,0)))
How to find Number of Days in Sql Server for a specific date
For Example
Declare @date datetime=''2012-11-25''
I have to find No. of days for @date (ie)Number of days for November month
My answer should be 30
解决方案
try below code:-
SELECT DATEPART(day, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,'2011-02-25')+1,0)))
try the below one and pass your requried month
SELECT DATEPART(dd, DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0)))
这篇关于如何在Sql Server中找到天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文