A friend ask to me to conversion about gregorian date to hijri date or hijri date to gregorian date. I will explan this conversions in this article.
First create a table with datetime datatype and insert a record on it.
1 2 3 4 5 6 7 8 |
USER [TESTDB] GO CREATE TABLE [dbo].[convert_gregorion_to_hijri_or_hijri_to_gregorian]( [created_date] [datetime] NULL ) ON [PRIMARY] GO INSERT INTO [dbo].[convert_gregorion_to_hijri_or_hijri_to_gregorian] VALUES('2019-01-22 00:00:00.000') |
Convert Gregorian Date to Hijri Date:
1 2 3 |
SELECT created_date ,CONVERT(varchar(50), created_date,131) AS [Hijri_Created_Date] FROM [TestDB].[dbo].[convert_gregorion_to_hijri_or_hijri_to_gregorian] |
Convert Hijri Date to Gregorian Date:
1 2 3 4 |
SELECT CONVERT(datetime, value, 131) FROM( values ('16/05/1440 12:00:00:000AM') ) samples(value) |