jdn_persian

Description

jdn_persian converts a provided Julian Day Number (i.e. the number of days since January 1 in the year 4713 BC) to the Persian (Shamsi) date.

Gory Details

Since the Persian calendar is a highly regular calendar, converting to and from a Julian Day Number is not as difficult as it looks. Basically it's a mather of dividing, rounding and multiplying.

This routine makes use of a herlper-routine, called Ceil, which is just an variation to the native VBA functions Fix and Int. You'll find the code of Ceil at the bottom of this page.

For detailed information on the calendar, see the page about the Persian Calendar.

If you need to know the name of the month, use persian_monthName

Code section

Sub jdn_persian(jdn As Long, _
                ByRef iYear As Integer, _
                ByRef iMonth As Integer, _
                ByRef iDay As Integer)
    Dim depoch
    Dim cycle
    Dim cyear
    Dim ycycle
    Dim aux1, aux2
    Dim yday
    depoch = jdn - persian_jdn(475, 1, 1)
    cycle = Fix(depoch / 1029983)
    cyear = depoch Mod 1029983
    If cyear = 1029982 Then
        ycycle = 2820
    Else
        aux1 = Fix(cyear / 366)
        aux2 = cyear Mod 366
        ycycle = Int(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1
    End If
    iYear = ycycle + (2820 * cycle) + 474
    If iYear <= 0 Then
        iYear = iYear - 1
    End If
    yday = (jdn - persian_jdn(iYear, 1, 1)) + 1
    If yday <= 186 Then
        iMonth = Ceil(yday / 31)
    Else
        iMonth = Ceil((yday - 6) / 30)
    End If
    iDay = (jdn - persian_jdn(iYear, iMonth, 1)) + 1
End Sub

' We needed an alternative to Int and Fix.
' Int(8.4) = 8, Int(-8.4) = -9
' Fix(8.4) = 8, Fix(-8.4) = -8
' Ceil(8.4) = 9, Ceil(-8.4) = -9
Private Function Ceil(number As Single) As Long
    Ceil = -Sgn(number) * Int(-Abs(number))
' or
    'Ceil = CInt(number + (Sgn(number) * 0.5))
End Function

See also

Notes, Operators, persian_jdn, Persian calendar, persian_monthName

Last update

Julian Day Number:2452153
Civil (Gregorian) date:Friday, 31 August 2001
Julian date:Friday, 18 August 2001
Hebrew date:yom shishi, 12 Elul 5761
Islamic date:Al-Jum'ah, 12 Jumada II 1422
Persian date:Jomeh, 9 Shahrivar 1380

Back to Calendar Math.
mail me
Kees Couprie
Other pages by the same author.