Thread Tools Display Modes
11/28/14, 05:55 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
GetDiffBetweenTimeStamps example

is there a good example of using GetDiffBetweenTimeStamps ? I would like see if the difference between today and another day is greater than 30 days.
  Reply With Quote
11/29/14, 12:41 AM   #2
rkuhnjr
 
rkuhnjr's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 26
It returns the int64 of seconds between the two dates you pass in
You would just need to check that with math to see if it is > 30 days

You will probably have a hard time figuring out the future days time stamp than anything else. It is the standard unix epoch time and there are no functions in the API that let you pass in date parameters and get back the Time stamp, at least none that I saw, Hell I couldn't even find a consistent way to get the users local time stamp, GetTimeStamp() is UTC, but the formatters all return it in the users TZ so the conversion happens in there somewhere.

Lua Code:
  1. local timeDifInSecs = GetDiffBetweenTimeStamps(futureDate, GetTimeStamp())
  2. if (timeDifInSecs > 30*86400) then
  3.   -- Its longer than 30 days
  4. else
  5.  -- its not longer
  6. end

Last edited by rkuhnjr : 11/29/14 at 12:44 AM.
  Reply With Quote
11/29/14, 01:09 AM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Originally Posted by rkuhnjr View Post
It returns the int64 of seconds between the two dates you pass in
You would just need to check that with math to see if it is > 30 days

You will probably have a hard time figuring out the future days time stamp than anything else. It is the standard unix epoch time and there are no functions in the API that let you pass in date parameters and get back the Time stamp, at least none that I saw, Hell I couldn't even find a consistent way to get the users local time stamp, GetTimeStamp() is UTC, but the formatters all return it in the users TZ so the conversion happens in there somewhere.

Lua Code:
  1. local timeDifInSecs = GetDiffBetweenTimeStamps(futureDate, GetTimeStamp())
  2. if (timeDifInSecs > 30*86400) then
  3.   -- Its longer than 30 days
  4. else
  5.  -- its not longer
  6. end
great, thanks.
  Reply With Quote
11/29/14, 04:37 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
To get the difference between 2 different times (startTime and endTime) in milliseconds you could use this code:

Lua Code:
  1. --Set start point somewhere in your code
  2.     local startTime = GetGameTimeMilliseconds()
  3.  
  4.     --Set end point somwhere in your code
  5.     local endTime   = GetGameTimeMilliseconds()
  6.  
  7.     --Difference in milliseconds?
  8.     local differenceInMS = endTime - startTime
  9.     if differenceInMs > 0 then
  10.         --Difference in seconds
  11.         local differenceInS  = differenceInMS / 1000
  12.         --Difference in minutes
  13.         local differenceInMin  = differenceInS / 60
  14.         --Difference in hours
  15.         local differenceInH  = differenceInMin / 60
  16.         --Difference in days
  17.         local differenceInDays  = differenceInH / 24
  18.     end
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » GetDiffBetweenTimeStamps example


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off