PhSoft Docs

  Development Tools 

PL/SQL function that converts Gregorian dates to Hijri

Key Components
1. Input/Output
- Takes Gregorian date (`G_DATE`)
- Returns Hijri date as string (e.g., 01-ربيع الأول-1446)

2. Base Reference
Uses the Hijri epoch: 14 July 622 AD (`FGDATE`)

3. Variables
- `H_DAY/H_MONTH/H_YEAR`: Track Hijri date components
- `I_LOOP`: Days between input date and epoch
- `HY`: Leap year calculation helper

Conversion Process
1. Year Calculation
- Subtracts epoch date from input date to get total days (`I_LOOP`)
- Uses 30-year lunar cycles (11 leap years per cycle):
- Regular years = 354 days
- Leap years = 355 days
- Adjusts year count based on remaining days

2. Day/Month Calculation
- Processes remaining days using Hijri month rules:
- Odd months = 30 days (Muharram, Safar, etc.)
- Even months = 29 days
- Dhu al-Hijjah (12th month) varies:
- 30 days in leap years
- 29 days otherwise

3. Month Names
Uses Arabic month names via `DECODE`:

1 → محرم (Muharram)
3 → ريع الأول (Rabi' al-Awwal)
9 → رمضان (Ramadan)
12 → ذو الحجة (Dhu al-Hijjah)


4. Formatting
- Adds leading zeros to single-digit days/months
- Returns final string in DD-MonthName-YYYY format

Key Characteristics
- Algorithm Type: Approximate astronomical calculation
- Accuracy: Follows tabular Islamic calendar rules
- Limitations:
- Doesn't account for lunar sightings
- Uses fixed leap year pattern
- Month names require Unicode support

This implementation provides a practical conversion method for applications needing approximate Hijri dates without real-time moon observations.