29 April 2007

SQL Server Hijri (Hijra) Dates

(Source: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21866389.html)

Hijri Date
The SQL Server datetime data type supports only Gregorian dates, but you can use a conversion function to convert the Gregorian date to the Hijri date based on the Kuwaiti algorithm.

Conversion to and from the Hijri calendar is possible through the CONVERT intrinsic. There are two CONVERT styles that are available in SQL Server 2000 to support Hijri dates:

130—Returns the date using the Hijri calendar, in dd mon yyyy hh:mi:ss:mmmAM format.
131—Returns the date using the Hijri calendar, in dd/mm/yy hh:mi:ss:mmmAM format.
For example, to convert a Gregorian date to Hijri format with Transact-SQL, you would use syntax such as the following:

SELECT CONVERT(nchar, GETDATE(), 131)

This query will return a string such as the following in its result set:

7/05/1421 12:14:35:727PM

The reverse operation is also possible. The following syntax would be used to convert a Hijri date to Gregorian format:

SELECT CONVERT(datetime, ' 7/05/1421 12:14:35:727PM', 131)

This query would convert the date to SQL Server datetime type, which in SQL Query Analyzer would appear as follows:

2000-08-07 12:14:35.727

Note that SQL Server does not use the regional calendar settings included with Windows 2000, and any adjustment made in that regional setting for the Hijri date does not affect the conversion method of SQL Server.

Also, SQL Server date functions such as DateName, DatePart, and DateAdd work with the Gregorian calendar, so you must make your conversions programmatically during development.

   

Best regards,
Mohammad Al-Mohsin
http://mem9.net | http://mem999.spaces.live.com

Filed under:
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# physik said:

it's very good, thanks a lot!

many excellent pictures for you

http://pic.physi.cn

29 April 07 at 10:45 AM
# ABADI SAAD said:

THANK YOU VERY MUCH, GOD BLESS YOU

05 May 07 at 4:49 AM
# Bhram said:

Thanks a lot.

Short, and doesn't lack anything.

Said it all, and didn't take more than 2 minutes to read carefully.

How better can this be? it simply can't.

Thanks again.

27 September 07 at 9:37 PM
# Mohammed Khaja Najmuddin said:

Thanks a lot my friend.It is very helpful to me

26 May 08 at 7:08 AM
# Muhammad Shono said:

Thank you. But there is an issue with this approach, it uses the Hijri calendar NOT Umm Al-Qura calendar--the official calendar in Saudi Arabia and other countries. Umm Al-Qura is the default Islamic calendar on Windows Vista.

23 July 09 at 8:25 AM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Wael A. Kabli

I started working for Microsoft in 2006 after I graduated from King Fahd University of Petroleum and Minerals as a Software Engineer. Since then, I have joined Microsoft Consulting Services and started my career as an Information Worker and Application Development Consultant. A major portion of my work is helping our customers deploy and accelerate our technology adoption such as Microsoft Office SharePoint Server and .Net Framework. https://careers.microsoft.com/careers/en/gbl/ProfileWaelWE.aspx
Page view tracker