WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Compare date (https://www.wowinterface.com/forums/showthread.php?t=58837)

lol_i_need_ur_help 07-11-21 03:24 PM

Compare date
 
Hi i need to compare dates something like that:

Code:

local currentdate = date()

  *01/09/21*          *01/07/21*
if currentdate => *timespan or whatever* then

print('you should check site for updates')

end

But i totaly not understand how to do that, can i get some help?

kurapica.igas 07-11-21 08:38 PM

Lua Code:
  1. local time = os.time or _G.time
  2.  
  3. -- Use time API to get the timestamp
  4. local date1 = time{ year = 2012, month = 12, day = 20, hour = 0, min = 0, sec = 0 }
  5. local date2 = time{ year = 2012, month = 12, day = 21, hour = 0, min = 0, sec = 0 }
  6.  
  7. if math.floor(math.abs(date2 - date1) / (3600 * 24)) > 0 then
  8.     print("diff day")
  9. else
  10.     print("same day")
  11. end

lol_i_need_ur_help 11-17-21 04:24 AM

Well i found solution...
 
If someone looking for something like that...

Lua Code:
  1. local function b()
  2.     local c = {year = 2022, month = 01, day = 01, hour = 00, min = 00, sec = 00}
  3.     local d = time(c)
  4.     return d
  5. end
  6. -- Compare b() with pc date.
  7. local function e()
  8.     local f = time()
  9.     return f
  10. end
  11. local function g()
  12.     local function h(time)
  13.     local i = floor(time / 86400)
  14.     local j = floor(mod(time, 86400) / 3600)
  15.     local k = floor(mod(time, 3600) / 60)
  16.     local l = floor(mod(time, 60))
  17.     return format("%d days:%02d hours:%02d min:%02d sec", i, j, k, l)
  18.     end
  19.     local m = b() - e()
  20.     local n = h(m)
  21.     return n
  22. end
  23. if e() >= b() then
  24.     return message("Your addon outdate!\n\n|cffFFFFFFOpen curse find|r |cff00ff52AddonName|r|cffFFFFFF. \n\ Download new update.|r")
  25. end


All times are GMT -6. The time now is 08:34 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI