Author Topic: Time interval counting  (Read 2665 times)

0 Members and 1 Guest are viewing this topic.

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Time interval counting
« on: 03 January, 2009, 15:48:59 »
thanks buddy can work will try that right now,

but i have one more thing for u to help me out :D

how can i find the date 5 days before today, i know this sounds funny bt here is wat i wanna do

i wanna keep logs of all last 4 days share by the user, so on every 5th day, the 5 days earlier share shud be deleted.

so i wud get the date of today with os.date("%D") bt how do i find the date 5 days prior from today.

thanks satya

Eyes says everything,
Its on you how u read em...

PtokaX forum

Time interval counting
« on: 03 January, 2009, 15:48:59 »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 725
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Time interval counting
« Reply #1 on: 03 January, 2009, 17:59:22 »
This is another common problem you are facing. Let's see the code from plop:
Code: [Select]
-- The following 2 functions are
-- Copyright (c) 2005, plop
-- All rights reserved.
JulianDate = function(tTime)
  tTime = tTime or os.date("*t")
  return os.time({year = tTime.year, month = tTime.month, day = tTime.day,
    hour = tTime.hour, min = tTime.min, sec = tTime.sec}
  )
end

JulianDiff = function(iThen, iNow)
  return os.difftime( (iNow or JulianDate()) , iThen)
end
-- End of plop's code

Explanation is here.
Everything could have been anything else and it would have just as much meaning.

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: Time interval counting
« Reply #2 on: 04 January, 2009, 14:55:04 »
American Idiot with ur xplanation i understood lil bit, bt again i m not gettin wat to do and how. it will be better if u can xplain me with an example pls.

i think for u to explain in a better way i will show u wat i m tryin to do.

Code: [Select]
sHare={}
LogShare = function(user,data)
nIK=user.sNick:lower()
if sHare[os.date("%D")] then
if sHare[os.date("%D")][nIK] then
table.insert (sHare[os.date("%D")][nIK],data)
SaveRecords()
else
sHare[os.date("%D")][nIK]={}
table.insert (sHare[os.date("%D")][nIK],data)
SaveRecords()
end
else
sHare[os.date("%D")]={}
sHare[os.date("%D")][nIK]={}
table.insert (sHare[os.date("%D")][nIK],data)
SaveRecords()
end
return
end

And heres how to table looks like:

Code: [Select]
sHare = {
["01/03/09"] = {
["pharoh"] = {
[1] = "yes man",
},
["allan"] = {
[1] = "bedtime stories",
[2] = "red line",
},
["cody"] = {
[1] = "LOST Se 4",
},
},
}


So here as u see dat i m storing the data in the table according to date as indices as said by American Idiot. Now the reason for this is after 5 days i want the records of the date 5 days prior to today can be easily deleted. which i want to do wen the script starts. For which i want to get a Date wich will be 5 days prior to todays date.

i don know bt i think i m sounding stupid, bt it will be great if u can xplain with a function wich takes arg as date and returns date wich is 5 days prior to arg date.

and in ur post u said

Quote
This would mean you need to parse that date before you make comparisons.
wat did u meant with dat can u xplain me pls.

it will be really great if u guys can xplain with examples pls

thanks satya

Eyes says everything,
Its on you how u read em...

Offline satya

  • Fulll Member
  • ****
  • Posts: 64
  • Karma: +3/-5
Re: Time interval counting
« Reply #3 on: 05 January, 2009, 15:20:50 »
Hey wats happenin? Where are the mods is there anyone to help pls. :(

Eyes says everything,
Its on you how u read em...

PtokaX forum

Re: Time interval counting
« Reply #3 on: 05 January, 2009, 15:20:50 »