How to save Hijri dates in sql server tables? What type of column?

后端 未结 4 828
无人及你
无人及你 2021-01-18 18:21

How to save Hijri dates (0000/01/01-9999/01/01) in Microsoft SQL Server tables? What type of column?
I choose datetime2, is it right?

CRE         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 18:41

    You can use column of type (Hijri_Date varchar(10)) and it will be easy to save and easy to make reports and query between 2 dates. In C# asp.net use the following steps:

    1- Add script manager to your web-form. and set the property EnableScriptGlobalization = true , EnableScriptLocalization = true

    2- Add HijriDate text box.

    3- Add Button to select Hijri Date.

    4- Add CalendarExtender from Ajaxtoolbox and add the following properties for example PopupButtonID="btnDate" TargetControlID="txtapptdate".

    5- Change the format property for CalendarExtender to dd/MM/yyyy.

    6- change the property for text-box read only = true.

    7- Add the following culture values to your header page in html to convert calender from Gregorian date to Hijri date : UICulture="ar" Culture="ar-SA".

    8- When you save and insert to SQL server the date you can use the value as usual Hijri_Date.Text

    9- to compare later and make filter and search screen or reports and if you need to find out the records between 2 dates use the format function to change the DATE output format and convert function to convert varchar to date in select statement like this:

    select format(cast(Hijri_date as date),'dd/MM/yyyy','ar-sa') 
    from Table1 
    where  Hijri_date between '10/05/1439' and '20/10/1439'
    

提交回复
热议问题