19.04.2022, 07:31
Here's my solution
Code:
sday, smonth, syear = 1, 2, 1999
eday, emonth, eyear = 2, 3, 2022
monthdiff = emonth - smonth
yeardiff = eyear - syear
daydiff = eday - sday
if daydiff < 0 then
leap = ((eyear % 4 == 0) and (eyear % 100 ~= 0)) or (eyear % 400 == 0)
mdays = { 31, (leap and 29 or 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
if emonth == 1 then
emonth = 12
else
emonth = emonth - 1
end
daydiff = daydiff + mdays[ emonth ]
monthdiff = monthdiff - 1
end
if monthdiff < 0 then
monthdiff = monthdiff + 12
yeardiff = yeardiff - 1
end
log(daydiff, monthdiff, yeardiff)