Here is a pure Excel solution, which does not require an internet connection or Power Query.
Disclaimer: I've found the function here and made some modifications to make it more readable. BTW, I've tested the function for the period 1396/07/01
to 1401/07/01
and it works OK, but use it with extensive testing and at your own risk.
Basically, the function calculates the total days since 1278/10/11
Shamsi (which is equal to the Excel date origin, 1900-01-01
). The result of the function is an integer (date value).
Below, you will find the solution in two formats, one using the new LET
function (for Excel 2021 and Office 365) and one without:
Note that the Shamsi date should be in the format 1401/07/21
.
Using LET
:
=LET(
y,VALUE(LEFT(A1,4)),
m,VALUE(MID(A1,6,2)),
d,VALUE(RIGHT(A1,2)),
full_months,IF((m-1)<7,(m-1)*31,IF((m-1)>6,(m-1)*30+6)),
total,(y-1)*365+full_months+d+INT((y-1)/4),
IF(MOD(y,4)=0,total+1,total)-466710
)
Legacy version:
IF(
MOD(VALUE(LEFT(A1,4)),4)=0,
(VALUE(LEFT(A1,4))-1)*365+(
IF(
(VALUE(MID(A1,6,2))-1)<7,
(VALUE(MID(A1,6,2))-1)*31,
IF(
(VALUE(MID(A1,6,2))-1)>6,
(VALUE(MID(A1,6,2))-1)*30+6
)
)
)+VALUE(RIGHT(A1,2))+INT((VALUE(LEFT(A1,4))-1)/4)+1,
(VALUE(LEFT(A1,4))-1)*365+(
IF(
(VALUE(MID(A1,6,2))-1)<7,
(VALUE(MID(A1,6,2))-1)*31,
IF(
(VALUE(MID(A1,6,2))-1)>6,
(VALUE(MID(A1,6,2))-1)*30+6
)
)
)+VALUE(RIGHT(A1,2))+INT((VALUE(LEFT(A1,4))-1)/4)
)-466710
To convert the resulting integer to date, either change the cell format to Date
or use the following formula:
TEXT(A2,"yyyy-mm-dd")