21 Feb 2013

Using Hijri Calendar in Oracle


select
to_char(sysdate,'fmday dd month yyyy','nls_calendar=''Arabic Hijrah''') Arab_Hijra,
to_char(sysdate,'fmday dd month yyyy','nls_calendar=''English Hijrah''') English_Hijra,
to_char(sysdate,'fmday dd month yyyy','nls_calendar=''gregorian''') Geor
from dual ;

In Arab Hijra we need to set
alter session set nls_calendar = 'Arabic Hijrah';
gives the names of the Hijrah months in Arabic

Regarding Arab Hijra we can used English Hijra.

NLS_CALENDAR

Property Description
Parameter type String
Syntax NLS_CALENDAR = "calendar_system"
Default value None
Modifiable ALTER SESSION
Range of values Any valid calendar format name
Basic No
NLS_CALENDAR specifies which calendar system Oracle uses. It can have one of the following values:
  • Arabic Hijrah
  • English Hijrah
  • Gregorian
  • Japanese Imperial
  • Persian
  • ROC Official (Republic of China)
  • Thai Buddha
    select
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''Arabic Hijrah''') Arab_Hijra,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''English Hijrah''') English_Hijra,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''gregorian''') Geor,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''Japanese Imperial''') Japan,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''Persian''') Persian,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''ROC Official''') China,
    to_char(:PF_FROM_DATE ,'fmday dd month yyyy','nls_calendar=''Thai Buddha''') Thai
    from dual;
 
ARAB_HIJRA ENGLISH_HIJRA GEOR JAPAN PERSIAN CHINA THAI
friday 5 ¿¿¿¿ ¿¿¿¿¿¿ 1424 friday 5 Rabi' Thani 1424 friday 6 june 2003 friday 6 6¿ 15 friday 16 Khordad 1382 friday 6 6¿ 92 friday 6 ¿¿¿¿¿¿¿¿ 2546

For example, suppose NLS_CALENDAR is set to "Japanese Imperial", the date format is "E YY-MM-DD". ("E" is the date format element for the abbreviated era name.) If the date is May 15, 1997, then the SYSDATE is displayed as follows:
SELECT SYSDATE FROM DUAL;
SYSDATE
--------
H 09-05-15

2 comments:

  1. I appriciated and also shared with my office mates...

    ReplyDelete
  2. How to store Hijri Dates in Date datatype field..
    I am getting error for this..
    select
    --to_date(to_char(to_date('29/10/2019','dd/mm/yyyy'),'dd/mm/yyyy','nls_calendar=''English Hijrah'''),'dd/mm/yyyy') ,
    to_char(to_date('29/10/2019','dd/mm/yyyy'),'dd/mm/yyyy','nls_calendar=''English Hijrah''')
    from dual;

    result :- 29/02/1441

    ReplyDelete