Compare two hours

Compare two hours

Postby Marco Turco » Sun Mar 29, 2009 2: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Compare two hours

Postby Armando » Sun Mar 29, 2009 2: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
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Compare two hours

Postby pablovidal » Sun Mar 29, 2009 2:37 pm

Code: Select all  Expand view


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
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: Compare two hours

Postby Rick Lipkin » Sun Mar 29, 2009 3:19 pm

Just a quick observation .. why can't you not change them to values and compare the numbers ?

Code: Select all  Expand view

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

 



Code: Select all  Expand view


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
Last edited by Rick Lipkin on Sun Mar 29, 2009 4:11 pm, edited 3 times in total.
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Compare two hours

Postby sygecom » Sun Mar 29, 2009 3:39 pm

For xHarbour:
MsgInfo(ElapTime( "10:55:00", "13:44:00" ))
User avatar
sygecom
 
Posts: 51
Joined: Tue Mar 11, 2008 3:18 am
Location: Brasil

Re: Compare two hours

Postby Marco Turco » Sun Mar 29, 2009 7: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Compare two hours

Postby Silvio » 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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: Compare two hours

Postby Zupan Miran » Thu Apr 02, 2009 7:25 am

I use this function:
Code: Select all  Expand view

Function DRazlika(dStartDate,cStartTime,dEndDate,cEndTime)
Return (((dEndDate - dStartDate) * 86400) - TimeToSec(cStartTime)) + TimeToSec(cEndTime)
 


... and in PRG code is somethnig like this
Code: Select all  Expand view

//*** 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
Zupan Miran
 
Posts: 5
Joined: Mon Mar 30, 2009 9:06 pm
Location: Slovenia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 34 guests