Home >Database >Mysql Tutorial >sql 判断给定日期所在年是否闰年语句

sql 判断给定日期所在年是否闰年语句

WBOY
WBOYOriginal
2016-06-07 17:47:403892browse

sql 判断给定日期所在年是否闰年语句
--根据全年总天数判断
declare @date datetime;
set @date = getdate()
select case datediff(day,dateadd(year,datediff(year,0,@date),0),dateadd(year,1+datediff(year,0,@date),0))
  when 365 then '平年' else '闰年' end
--根据二月天数判断
--给日期的上一年最后一天加2个月,即为当年2月最后一天
select case day(dateadd(month,2,dateadd(year,datediff(year,0,@date),-1))) when 28 then '平年' else '闰年' end
go

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn