Compare two hours

Post Reply
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Compare two hours

Post by Marco Turco »

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
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: Compare two hours

Post by Armando »

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
pablovidal
Posts: 398
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana
Contact:

Re: Compare two hours

Post by pablovidal »

Code: Select all


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
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Compare two hours

Post by Rick Lipkin »

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

Code: Select all

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

 

Code: Select all


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
sygecom
Posts: 42
Joined: Tue Mar 11, 2008 3:18 am
Location: Brasil

Re: Compare two hours

Post by sygecom »

For xHarbour:
MsgInfo(ElapTime( "10:55:00", "13:44:00" ))
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Compare two hours

Post by Marco Turco »

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

Re: Compare two hours

Post by Silvio »

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

Re: Compare two hours

Post by Zupan Miran »

I use this function:

Code: Select all

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

//*** 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
Post Reply