mIRC Homepage
Posted By: Malokai Difference between two times - 17/09/10 05:24 PM
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
Posted By: jaytea Re: Difference between two times - 17/09/10 05:35 PM
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))
Posted By: firefox Re: Difference between two times - 17/09/10 05:39 PM
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

Posted By: Malokai Re: Difference between two times - 17/09/10 07:43 PM
Thank you BOTH smile I was unaware of the $ctime function smile Many thanks once again smile
© mIRC Discussion Forums