This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

calculate diferent between years, month, days
#6
Thanks, I choose to use the one of admin and changed it a little, so he calculates the different between today and the set day.
But both thanks for helping me.

Code:
now = os.date('*t')


eday = now.day
emonth = now.month
eyear = now.year

-- bevrijdingsdag
sday, smonth, syear = 5, 5, 1945

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

grp.checkupdate('62/7/51', yeardiff ..' jaar ' .. monthdiff ..' maanden ' .. daydiff ..' dagen ')
Reply


Messages In This Thread
RE: calculate diferent between years, month, days - by Dré - 27.04.2022, 13:18

Forum Jump: