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.
As you can see, the Gregorian date has been converted to the Hijri date.
Good luck to everyone in business and life.