FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Compare two hours
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Compare two hours
Posted: Sun Mar 29, 2009 02:12 PM

Hi,
anyone know a function to compare two hours ?

Imagine you have cTime1="10.55" and cTime2="13.44",
is there a function to know if cTime1>cTime2 ?

Thanks in advance

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Compare two hours
Posted: Sun Mar 29, 2009 02:35 PM

Marco:

Take a look at the TimeToSec function of xHarbour.

This function converts the time in seconds and then you can compare seconds against seconds

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 401
Joined: Thu Oct 06, 2005 10:15 PM
Re: Compare two hours
Posted: Sun Mar 29, 2009 02:37 PM
Code (fw): Select all Collapse
Local cTime1 := "10:00"
Local cTime2 := "13:20"

If TimeAsSeconds( cTime1 ) <= TimeAsSeconds( cTime2 )
 ....
EndIf

FUNCTION TimeAsSeconds( cTime )
RETURN VAL( cTime ) * 3600 + VAL( SUBSTR( cTime, 4 ) ) * 60 + VAL( SUBSTR( cTime, 7 ) )
Saludos,



Pablo Alberto Vidal

/*

------------------------------------------------------

Harbour 3.2.0, Fivewin 17.02, BCC7

------------------------------------------------------

*/
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Compare two hours
Posted: Sun Mar 29, 2009 03:19 PM
Just a quick observation .. why can't you not change them to values and compare the numbers ?

Code (fw): Select all Collapse
Imagine you have cTime1="10.55" and cTime2="13.44",
is there a function to know if cTime1>cTime2 ?



Code (fw): Select all Collapse
lOK := .F.

nTIME1 := VAL("10.55")
nTIME2 := VAL("13.44")

nDIFF := nTIME1 - nTIME2

IF nDIFF > 0
    lOK := .T.   
ELSE
    lOK := .F.
ENDIF

RETURN(lOK)


On the other hand still as "char" cTime2 would always be greater than cTime1 as you have them defined .. am I missing something here ?? :-)


Rick Lipkin
Posts: 58
Joined: Tue Mar 11, 2008 03:18 AM
Re: Compare two hours
Posted: Sun Mar 29, 2009 03:39 PM

For xHarbour:
MsgInfo(ElapTime( "10:55:00", "13:44:00" ))

Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Compare two hours
Posted: Sun Mar 29, 2009 07:05 PM

Ok. I am using TimeToSec() for this special situation.

Thanks to all for the great support.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: Compare two hours
Posted: Tue Mar 31, 2009 10:10 AM
Marco Turco wrote:Hi,
anyone know a function to compare two hours ?

Imagine you have cTime1="10.55" and cTime2="13.44",
is there a function to know if cTime1>cTime2 ?

Thanks in advance


Marco,
when I come back home Ican send you a function
( date1,ora1,date2,ora2)
I use it to rent beach services
Best Regards, Saludos



Falconi Silvio
Posts: 5
Joined: Mon Mar 30, 2009 09:06 PM
Re: Compare two hours
Posted: Thu Apr 02, 2009 07:25 AM
I use this function:
Code (fw): Select all Collapse
Function DRazlika(dStartDate,cStartTime,dEndDate,cEndTime)
Return (((dEndDate - dStartDate) * 86400) - TimeToSec(cStartTime)) + TimeToSec(cEndTime)


... and in PRG code is somethnig like this
Code (fw): Select all Collapse
//*** End_Time, Start_Time are string ("12:15", "13:15") 
        dd2 :=alltrim(End_Time)
        dd1 :=alltrim(Start_Time)
        dd3 :=DRazlika(@StartDate,@dd1,@End_Date,@dd2)    //*** Return dd3 in seconds
        dd4 :=int(dd3/86400)                           //*** No of days
        dd5 :=dd3-(dd4*86400)                         
        dd6 :=int(dd5/3600)                            //*** No in hours
        dd7 :=(dd5-dd6*3600)/60                     //*** rest in minutes
...
...
 @ row ,4 say "Result: "+str(dd4,2)+" days "+str(dd6,2)+" hours "+str(dd7,2)+" min"


Regards
Zupan Miran
Slovenia

Continue the discussion