Bolodefchoco_LUAXML

[Function] Idade

Sep 8th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 08/09/2015
  3. --Last update: 16/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Retorna a idade exata de acordo com a data inserida.
  7.     Args:
  8.         day --> Caso seja número, deverá ser DD do dia de nascimento, caso seja string, deverá ser "DD/MM/AAAA"
  9.         month --> Caso day seja número, deverá ser MM do mês de nascimento.
  10.         year --> Caso day seja número, deverá ser AAAA do ano de nascimento.
  11. ]]--
  12.  
  13. age = function(day,month,year)
  14.     if type(day) == "string" then
  15.         day,month,year = day:match("(%d+)/(%d+)/(%d+)")
  16.     end
  17.     day,month,year = tonumber(day),tonumber(month),tonumber(year)
  18.     local cDay,cMonth,cYear = tonumber(os.date("%d")),tonumber(os.date("%m")),tonumber(os.date("%Y"))
  19.     return year<=cYear and (((month>cMonth or month==cMonth and day>cDay) and cYear-year-1 or (month==cMonth and day<=cDay or month<cMonth) and cYear-year)) or 0
  20. end
Advertisement
Add Comment
Please, Sign In to add comment