MSSQL – calculate season


SELECT
(case
		when month(GETDATE()) = 12  then case when day(GETDATE()) < 21 then 'autumn' else 'winter' end
		when month(GETDATE()) in ( 1,2 ) then 'winter'
		when month(GETDATE()) = 3 then case when day(GETDATE()) < 21 then 'winter' else 'spring' end
		when month(GETDATE()) in ( 4, 5 ) then 'spring'
		when month(GETDATE()) = 6  then case when day(GETDATE()) < 21 then 'spring' else 'summer' end
		when month(GETDATE()) in ( 7, 8 ) then 'summer'
		when month(GETDATE()) = 9  then case when day(GETDATE()) < 23 then 'summer' else 'autumn' end
		when month(GETDATE()) in ( 10, 11 ) then 'autumn'
end) as season

Comments are closed.