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.

convert timeago mysql

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

convert timeago mysql

Post by heman »

I need some help, i search around this forum, but couldnt find what im looking for.

Here goes:


Nicks are stored in a mysql database with the time the nick is added (datetime) like: 2007-19-01 20:01:02 (row is called "addtime")


To find how long ago the nick was stored the script use the folowing:

Code: Select all

 set temp [mysqlsel $db "select *,SEC_TO_TIME(unix_timestamp(now()) - unix_timestamp(addtime)) as data from table WHERE .....


Now it returns someting like:

nick added to the db 17:50:57 ago
nick added to the db 25:50:57 ago
nick added to the db 339:50:57 ago
etc.


Im trying it will return the time after 24:00:00 like 1day 1hour 50min and 57 sec ago.

Same with weeks ,months, years


Any idea what i can add to the script to let it announce like this?

Thanks.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

proc timeAgo t {
 foreach {h m s} [split $t :] {
  set unixt [clock scan "$h hours $m minutes $s seconds ago"]
  break
 }
 duration [expr {[unixtime]-$unixt}]
}
« Opposing » .tcl proc timeAgo t {foreach {h m s} [split $t :] {set unixt [clock scan "$h hours $m minutes $s seconds ago"];break} ; duration [expr {[unixtime]-$unixt}]}
« Bot » Tcl:
« Opposing » .tcl timeAgo 339:50:57
« Bot » Tcl: 2 weeks 3 hours 50 minutes 57 seconds
h
heman
Voice
Posts: 13
Joined: Sat Dec 30, 2006 3:17 pm

Post by heman »

that worked :)

Thanks.


But now I have an other problem while testing the script :(

So please take a look at:
http://forum.egghelp.org/viewtopic.php?p=69757#69757

Thanks
Post Reply