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.

Compare two date/time Strings

Help for those learning Tcl or writing their own scripts.
Post Reply
r
retan
Voice
Posts: 5
Joined: Mon Jun 11, 2007 11:10 pm

Compare two date/time Strings

Post by retan »

Hello
I have a date/time string like this: 30.12.2006 and 10:12:53
I want that this string is compared with the UNIX time (the time of the server where the eggdrop is running) and the difference to be outputted in this format:
xx years xx months xx days xx hours xx minutes xx seconds

How can I do that?
Thanks!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, you'd have to convert that into something usable with clock scan.
Once you've converted it to an integer clock value (unixtime), use expr to calculate the diff (current time can be obtained from clock seconds), and use the eggdrop-speciffic command duration to format the output into something human-readable.

I'd probably do it something like this:

Code: Select all

proc timediff {date time} {
 set t [split $date "."]
 return [duration [expr [clock seconds] - [clock scan "[lindex $t 2][lindex $t 1][lindex $t 0]T${time}"]]]
}
NML_375
Post Reply