This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

error calculating datetime

Help for those learning Tcl or writing their own scripts.
Post Reply
h
heman
Voice
Posts: 13
Joined: Sat Dec 30, 2006 3:17 pm

error calculating datetime

Post by heman »

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
2007-01-17 20:11:43

The script uses:

Code: Select all

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:
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: Select all

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:
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:
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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

To calculate the time difference between addtime and time now, use:

Code: Select all

duration [expr {[unixtime]-[clock scan <addtime>]}]
example:
.tcl duration [expr {[unixtime]-[clock scan "2007-01-17 20:11:43"]}]
Tcl: 2 days 20 hours 42 minutes 50 seconds
h
heman
Voice
Posts: 13
Joined: Sat Dec 30, 2006 3:17 pm

Post by heman »

Any idea how i can insert that into the script?

script us

Code: Select all

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.
Post Reply