mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2010
Posts: 6
M
Malokai Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Sep 2010
Posts: 6
I desperately need some help here please. I need to write an alias that will return the difference in seconds between 2 times. That in itself is pretty simple, however, there is also the date to consider. For example:

If Time1 = 23:00:00 and Date1 = 13/09/2010 and Time2 = 00:01:00 and Date2 = 14/09/2010, then obviously the difference in times would be 3660 seconds. But I'm having problems if there's quite a difference between the times/date.

I'd like to be able to do something like:

Var %DifferenceResult $Difference(%Time1,%Date1,Time2,%Date5)
Msg $Nick Difference = $Duration(%DifferenceResult)

ANY help would be greatly appreciated smile

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
you can use $ctime to convert a date and time into a Unix timestamp, an integer from which other timestamps can easily be compared. here's an example:

Code:
var %time1 = 23:00:00, %date1 = 13/09/2010, %time2 = 00:01:00, %date2 = 14/09/2010
var %DifferenceResult = $ctime(%time1 %date1) - $ctime(%time2 %date2)
msg $nick Difference = $duration($abs(%DifferenceResult))


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Sep 2007
Posts: 202
F
Fjord artisan
Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
convert your times to ctime and then take one away from the other

var %firsttime $ctime(%date1 %time1)
var %secondtime $ctime(%date2 %time2)

msg $nick Difference = $calc(%secondtime - %firsttime) seconds

you may want to manipulate the result with http://www.mircscripts.org/comments.php?cid=2861

edit: heh jaytea was faster


Last edited by firefox; 17/09/10 05:40 PM.
Joined: Sep 2010
Posts: 6
M
Malokai Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Sep 2010
Posts: 6
Thank you BOTH smile I was unaware of the $ctime function smile Many thanks once again smile


Link Copied to Clipboard