计算给定月份中的天数 [英] counting number of days in a given month
本文介绍了计算给定月份中的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IF Exists (
select 1 where month(getdate()) IN (1,3,5,7,8,10,12)
)
我没有获得此代码产生的错误的解决方案,任何人都可以帮助我.
Shiv
i am not getting the solution for the error which this code is generting, can any one help me.
Shiv
推荐答案
u如果不使用,可以使用它
u can use this if it not comming
CREATE FUNCTION [dbo].[ufn_GetDaysInMonth] ( @pDate DATETIME )
RETURNS INT
AS
BEGIN
RETURN CASE WHEN MONTH(@pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN MONTH(@pDate) IN (4, 6, 9, 11) THEN 30
ELSE CASE WHEN (YEAR(@pDate) % 4 = 0 AND
YEAR(@pDate) % 100 != 0) OR
(YEAR(@pDate) % 400 = 0)
THEN 29
ELSE 28
END
END
END
GO
这至少对我有用...
This at least works for me...
if exists(select 1 where month(getdate()) IN (1,3,5,7,8,10,12))
begin
select 'Exists'
end
else
begin
select 'Don''t exists'
end
这篇关于计算给定月份中的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文