Function SHAMSI_MILADI(YYYY, MM, DD) As Date
If MM > 6 Then
DIF = 186 + (MM - 7) * 30 + DD
Else
DIF = 31 * (MM - 1) + DD
End If
For YY = 0 To YYYY - 1301
If YY Mod 4 = 3 Then
DIF = DIF + 366
Else
DIF = DIF + 365
End If
Next
SHAMSI_MILADI = DateAdd("D", DIF, "1921/3/20")
End Function
Function MILADI_SHAMSI(YYYY, MM, DD) As String
D1 = DateSerial(YYYY, MM, DD)
DIF = DateDiff("d", D1, "1921/3/20")
Y = 1300
DAYS = 365
Do While DIF > DAYS
DIF = DIF - DAYS
Y = Y + 1
If Y Mod 4 = 3 Then
DAYS = 366
Else
DAYS = 365
End If
Loop
If DIF > 186 Then
DIF = DIF - 186
M = (DIF \ 30) + 7
D = DIF Mod 30
Else
M = (DIF \ 31) + 1
D = DIF Mod 31
End If
MILADI_SHAMSI = CStr(Y) & "/" & CStr(M) & "/" & CStr(D)
End Function