# Gregorian date to Solar (Iran) date

## Recommended Posts

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 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

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...