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
#2
Not fully tested but something like this could work (however always tricky with leap years):
Code:
startdate = {
  day = 2,
  month = 9,
  year = 2006
}

enddate = {
  day = 16,
  month = 4,
  year = 2022
}

unixstart = os.time(startdate)
unixend = os.time(enddate)

if unixend < unixstart then
  log('Start date is higer then the end date, exiting script')
  return
end

seconds = os.difftime(unixend, unixstart)
timediff = os.date('!*t', seconds)

years = timediff.year - 1970
months = timediff.month - 1
days = timediff.day - 1

log(years,months,days)
Reply


Messages In This Thread
RE: calculate diferent between years, month, days - by Erwin van der Zwart - 17.04.2022, 13:52

Forum Jump: