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 

Compare two date/time Strings

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


Joined: 11 Jun 2007
Posts: 5

PostPosted: Sat Jul 21, 2007 9:55 am    Post subject: Compare two date/time Strings Reply with quote

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!
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 21, 2007 10:19 am    Post subject: Reply with quote

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:
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, idling at #eggdrop@IrcNET
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