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 fromat in SQL Server.

With respect to 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 in correct.

With respect to SQL Server 2012:

SQL Serverer 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.

Enjoy 🙂

Advertisements

2 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s