How to convert Gregorian dates to Hijri date in SQL Server 2008 – 2012

In this hint, I will explain How to

Convert Gregorian dates to Hijri dates format in SQL Server.


Convert Gregorian dates to Hijri dates format in SQL Server 2012

SQL Server 2012 introduces a new Format function that used to achieve the same result.

SELECT FORMAT ( GETDATE(), 'dd/MM/yyyy', 'ar-SA' )
Output
16/08/1435

Note: There is no issue to use the previous SQL Server 2008 queries within SQL Server 2012.


Convert Gregorian dates to Hijri dates format in SQL Server 2008

SELECT convert(nvarchar(10),GetDate(),131)
Output
16/08/1435

If you need to show the month name you can replace 131 with 130


SELECT convert(nvarchar(15),GetDate(),130)

Output
16 شعبان 1435

Note: you should use “nvarchar” to show Arabic month name correctly.


Applies To
  • SQL Server 2012.
Advertisements

3 thoughts on “How to convert Gregorian dates to Hijri date in SQL Server 2008 – 2012

  1. I’m certainly happy to found out this blog please keep up ,and I’ll be bookmarking it and checking back often!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s