egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

error calculating datetime

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
heman
Voice


Joined: 30 Dec 2006
Posts: 13

PostPosted: Sat Jan 20, 2007 10:39 am    Post subject: error calculating datetime Reply with quote

While testing the script, i found a problem

The script I use, stores nicks with date and time in mysql db

The row, thats stores date now, is called addtime:

Made it like this: 'addtime datetime'

This row stores datetime like this

Quote:

2007-01-17 20:11:43



The script uses:

Code:

set data [mysqlsel $db "select *,SEC_TO_TIME(unix_timestamp(now()) - unix_timestamp(pretime)) as data from $table WHERE nick like '%$keyed%' GROUP BY data;" -list]


To calculate time between addtime and time now.


This will result in a output in hours, minutes and seconds. Example: 65:57:17

So the output looks someting like this:
Quote:

DATA -> NICK {2007-01-17 20:11:43} 65:57:17


In the earlier post (http://forum.egghelp.org/viewtopic.php?t=12983) i asked to change the time output (65:57:17) to seconds, minutes, hours, days etc

Code:

proc fixTime {daTime} {
 foreach {h m s} [split $daTime :] {
  set unixt [clock scan "$h hours $m minutes $s seconds ago"]
  break
 }
 duration [expr {[unixtime]-$unixt}]
}


That worked, so it announce in the irc channel someting like this:
Quote:

NICK - Added 2 days 17 hours 57 minutes 7 seconds ago


So everyting works great


But now the problem:

When a nick is added longer then about 4 weeks 6 days 22 hour 59 minutes and 59 seconds ago (838:59:59), it keeps announcing 4 weeks 6 days 22 hour 59 minutes and 59 seconds (838:59:59) even if the nick is added longer then that time ago.

data Examples:
Quote:

DATA -> nick1 {2006-11-19 18:46:13} 838:59:59
DATA -> nick2 {2006-11-22 01:59:23} 838:59:59
DATA -> nick3 {2006-11-27 09:22:19} 838:59:59


So the addtime is correct, but the calculated time between addtime and now time isnt, it keep telling its 838:59:59 (?)


Any idea what could be the problem?

Thanks
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jan 20, 2007 10:55 am    Post subject: Reply with quote

To calculate the time difference between addtime and time now, use:
Code:
duration [expr {[unixtime]-[clock scan <addtime>]}]

example:
Quote:
.tcl duration [expr {[unixtime]-[clock scan "2007-01-17 20:11:43"]}]
Tcl: 2 days 20 hours 42 minutes 50 seconds

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
heman
Voice


Joined: 30 Dec 2006
Posts: 13

PostPosted: Sat Jan 20, 2007 2:11 pm    Post subject: Reply with quote

Any idea how i can insert that into the script?

script us

Code:

set data [mysqlsel $db "select *,SEC_TO_TIME(unix_timestamp(now()) - unix_timestamp(pretime)) as data from $table WHERE nick like '%$keyed%' GROUP BY data;" -list]


to calculate the time difference between addtime and time now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber