Sign in to follow this  
Followers 0
FaridAgl

Gregorian date to Solar (Iran) date

3 posts in this topic

Maybe someone found it useful:

Func GregorianToSolar($iYear = @YEAR, $iMonth = @MON, $iDay = @MDAY)
    Local Const $aiDays[] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    Local $iDayOfYear = 0
    For $i = 1 To $iMonth - 1
        $iDayOfYear += $aiDays[$i - 1]
    Next

    $iDayOfYear += $iDay

    If ((Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0) Or (Mod($iYear, 400) = 0)) Then
        If ($iMonth > 2) Then $iDayOfYear += 1
    EndIf

    If ($iDayOfYear <= 79) Then
        If (Mod($iYear - 1, 4) = 0) Then
            $iDayOfYear += 11
        Else
            $iDayOfYear += 10
        EndIf

        $iYear -= 622

        If (Mod($iDayOfYear, 30) = 0) Then
            $iMonth = $iDayOfYear / 30 + 9
            $iDay = 30
        Else
            $iMonth = $iDayOfYear / 30 + 10
            $iDay = Mod($iDayOfYear, 30)
        EndIf
    Else
        $iYear -= 621
        $iDayOfYear -= 79

        If ($iDayOfYear <= 186) Then
            If (Mod($iDayOfYear, 31) = 0) Then
                $iMonth = $iDayOfYear / 31
                $iDay = 31
            Else
                $iMonth = $iDayOfYear / 31 + 1
                $iDay = Mod($iDayOfYear, 31)
            EndIf
        Else
            $iDayOfYear -= 186

            If (Mod($iDayOfYear, 30) = 0) Then
                $iMonth = $iDayOfYear / 30 + 6
                $iDay = 30
            Else
                $iMonth = $iDayOfYear / 30 + 7
                $iDay = Mod($iDayOfYear, 30)
            EndIf
        EndIf
    EndIf

    Return StringFormat("%u-%02u-%02u", $iYear, $iMonth, $iDay)
EndFunc

Share this post


Link to post
Share on other sites



I like the idea that "new year" is on 21st of March when winter is over and spring begins.

Seems to calculate Norūz properly.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I like the idea that "new year" is on 21st of March when winter is over and spring begins.

You know, it's somehow the best part of it.

 

Seems to calculate Norūz properly.

Yeap, exactly, the first 13 days of new year (which starts by the first day of spring) is called Norūz.

The above function converts a Gregorian date to a Solar date, for example:

ConsoleWrite(GregorianToSolar(1992, 02, 01) & @CRLF) ;Outputs: 1370-11-12, which is my birthday ^_^
Edited by D4RKON3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0