Converting Gregorian Date to Hijri Date in SQL Server

Hello to everyone,

In this article, I will give information about converting Gregorian date to Hijri date in SQL Server.

In SQL Server, in some cases, you may want to convert the Gregorian date to the Hijri date.

You can easily do this using the code below.

DECLARE @DateTime AS DATETIME;
SET @DateTime = GETDATE();

SELECT @DateTime AS [Gregorian Date],
       CONVERT(VARCHAR(11), @DateTime, 131) AS [Hijri Date]
UNION ALL
SELECT @DateTime AS [Gregorian Date],
       FORMAT(@DateTime, 'dd-MM-yyyy', 'ar') AS [Hijri Date]
UNION ALL
SELECT @DateTime AS [Gregorian Date],
       FORMAT(@DateTime, 'dd/MM/yyyy', 'ar') AS [Hijri Date]
UNION ALL
SELECT @DateTime AS [Gregorian Date],
       FORMAT(@DateTime, 'yyyy-MM-dd', 'ar') AS [Hijri Date]
UNION ALL
SELECT @DateTime AS [Gregorian Date],
       FORMAT(@DateTime, 'dddd/MMMM/yyyy', 'ar') AS [Hijri Date]
UNION ALL
SELECT @DateTime AS [Gregorian Date],
       FORMAT(@DateTime, 'dd-MM-yyyy', 'ar') AS [Hijri Date];
GO

When you run the above code, you will see the following result.

Converting Gregorian Date to Hijri Date in SQL Server

As you can see, the Gregorian date has been converted to the Hijri date.

Good luck to everyone in business and life.

244 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!