Seasonal Returning Function in SQL Server

Hello to everyone,

In this article, I will give information about the function that brings seasonal information in SQL Server.

In SQL Server you may want to fetch seasonal information in some cases.

You can easily do this with the help of the function below.

CREATE FUNCTION getSeasonInformation
(
    @Date DATETIME
)
RETURNS VARCHAR(20)
BEGIN

    RETURN (CASE
                WHEN MONTH(@Date) IN ( 12, 1, 2 ) THEN
                    'Winter'
                WHEN MONTH(@Date) IN ( 3, 4, 5 ) THEN
                    'Spring'
                WHEN MONTH(@Date) IN ( 6, 7, 8 ) THEN
                    'Summer'
                WHEN MONTH(@Date) IN ( 9, 10, 11 ) THEN
                    'Autumn'
            END
           );
END;

--Kullanımı

SELECT dbo.getSeasonInformation(GETDATE()) AS SeasonInformation

When you create the function and run the code, you will get a result like the one below.

Seasonal Returning Function in SQL Server

As you can see, the information on which season we are in is based on the entered date.

Good luck to everyone in business and life.

332 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!