Page 1 of 1 1
Topic Options
#162042 - 2006-05-18 06:03 PM Comparing Two times (HH:mm:ss)
Pants Offline
Lurker

Registered: 2006-05-18
Posts: 2
Is there a way to compare two times (HH:mm:ss) and if a difference of X do Y or ELSE do Z.

Why I want this:

I want to send an email when a particular alert occurs, however, I only want to send this email if two alerts happen within specified time frame, i.e. 30 seconds.

I was thinking of writing the two times into an INI file and then reading the values but I can't figure out how to compare these times and return a value which I can then say is greater than or less than the specified value.

Hope this makes sense.

Thanks in advance

Top
#162043 - 2006-05-18 07:09 PM Re: Comparing Two times (HH:mm:ss)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are several date math type UDFs posted, any one of which should do it for you. I prefer to convert everything to CTime and work with that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#162044 - 2006-05-18 09:15 PM Re: Comparing Two times (HH:mm:ss)
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is a date function that should be able to do the job for you...

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB2&Number=146619#Post146619

Top
#162045 - 2006-05-19 03:38 PM Re: Comparing Two times (HH:mm:ss)
Pants Offline
Lurker

Registered: 2006-05-18
Posts: 2
Thanks for the replies...

Found this UDF which worked a treat:

http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=149297&an=0&page=3#149297

Thanks again,

Andy

Top
#162046 - 2006-05-19 04:06 PM Re: Comparing Two times (HH:mm:ss)
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I'm a bit late to this party, but if you want the time difference for a sub 24 hour period then simple maths will do:

Code:
$sTime1="23:30:10"
$sTime2="01:40:30"

$iTimeDiff=(86400*($sTime1>$sTime2))
+(3600*Split($sTime2,":")[0]+60*Split($sTime2,":")[1]+Split($sTime2,":")[2])
-(3600*Split($sTime1,":")[0]+60*Split($sTime1,":")[1]+Split($sTime1,":")[2])

"Difference is : "+$iTimeDiff+@CRLF


Top
#162047 - 2006-05-19 04:14 PM Re: Comparing Two times (HH:mm:ss)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
well... if only a 24 hour clock is all there is to go on, it would be fraught with problems if time exceeds the 24 hour range. I thought it was too obvious to have to mention it but one should never assume...

It was also not mentioned whether the time is represented in a 24 hour format.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2009 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.148 seconds in which 0.113 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org