Click here to Skip to main content
14,425,302 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a small application in C# for data's read from Excel and then store the datas to Sql Server 2008. In Excel there is a column for Hijri_Date like dd/MM/yyyy format,

Example: 17/4/1432

I need to read from Excel and update it to SQl Server 2008. For that in sql server what datatype has to declare for this? either DateTime or datetime2 ?

And what will be the update statement?

Update MyTable set My_Hijri_Dt=?? where MyField1='MyValue';

Does anybody can give the details?

Thanks BY
Updated 10-Jun-19 0:34am
Rate this:
Please Sign up or sign in to vote.

Solution 1

I'm not 100% certain about this, but according to this[^] SQL server only supports Greogrian Dates. This makes some sense as al-Hijri is one of the few calendars that doesn't follow the solar year and the difficulty where lunar observations are applied. You can change a UTC date to a Hijri on using the cast/convert[^] functions if you want, but it's probably better to store do everything on the SQL server side in UTC, and write a function to convert to al-Hijri on the client.
[no name] 18-Jun-19 8:22am
Rate this:
Please Sign up or sign in to vote.

Solution 2

Declare @Hdate nvarchar(50)
set @Hdate = convert(varchar(10),convert(date,convert(varchar(12),@thedate,131),103),112)
CHill60 10-Jun-19 5:21am
Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.
almounkez 10-Jun-19 5:34am
Declare @Hdate nvarchar(50)
set @Hdate = convert(varchar(10),convert(date,convert(varchar(12),GETDATE(),131),103),112)
select @Hdate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100