mIRC Home    About    Download    Register    News    Help

Print Thread
Difference between two times #226066
17/09/10 05:24 PM
17/09/10 05:24 PM
Joined: Sep 2010
Posts: 6
M
Malokai Offline OP
Nutrimatic drinks dispenser
Malokai  Offline OP
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

Re: Difference between two times [Re: Malokai] #226068
17/09/10 05:35 PM
17/09/10 05:35 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
jaytea  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
Re: Difference between two times [Re: Malokai] #226069
17/09/10 05:39 PM
17/09/10 05:39 PM
Joined: Sep 2007
Posts: 202
F
firefox Offline
Fjord artisan
firefox  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.
Re: Difference between two times [Re: Malokai] #226071
17/09/10 07:43 PM
17/09/10 07:43 PM
Joined: Sep 2010
Posts: 6
M
Malokai Offline OP
Nutrimatic drinks dispenser
Malokai  Offline OP
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