Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Gregorian date to Hijri date

Posted on 2006-05-27
2
Medium Priority
?
10,220 Views
Last Modified: 2012-05-05
I am Having a table. On which i have one field whose data type datetime also i have the value data on that field, i am having another field whose data type is numeric which contains the arabic date(Hijri calendar date) this is null now.I want to update the arabic date field with the existing English from which i having in another field.
0
Comment
Question by:batchakamal
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 300 total points
ID: 16778155
try this,


update table_name set   hdate = convert(datetime, GETDATE(), 131)
where <condition>



==================

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.

===========

itsvtk

0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 16778167
Both fields must be datetime data type.

I assume fields names as Field1, Field2.  Field1 has English Date time. Field2 has null values.  Field1 & Field2 are datetime data type.

I assume table name is <table_name>

=============
update <table_name> set Field2 = convert( datetime, Field1, 131 )
=============


itsvtk



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question