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
Compare two hours
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Compare two hours
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
Re: Compare two hours
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
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
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
- pablovidal
- Posts: 398
- Joined: Thu Oct 06, 2005 10:15 pm
- Location: Republica Dominicana
- Contact:
Re: Compare two hours
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
------------------------------------------------------
*/
Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
- Rick Lipkin
- Posts: 2397
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Compare two hours
Just a quick observation .. why can't you not change them to values and compare the numbers ?
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
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)
Rick Lipkin
Last edited by Rick Lipkin on Sun Mar 29, 2009 4:11 pm, edited 3 times in total.
Re: Compare two hours
For xHarbour:
MsgInfo(ElapTime( "10:55:00", "13:44:00" ))
MsgInfo(ElapTime( "10:55:00", "13:44:00" ))
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Compare two hours
Ok. I am using TimeToSec() for this special situation.
Thanks to all for the great support.
Thanks to all for the great support.
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
Re: Compare two hours
Marco,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
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
Falconi Silvio
-
- Posts: 5
- Joined: Mon Mar 30, 2009 9:06 pm
- Location: Slovenia
- Contact:
Re: Compare two hours
I use this function:
... and in PRG code is somethnig like this
Regards
Zupan Miran
Slovenia
Code: Select all
Function DRazlika(dStartDate,cStartTime,dEndDate,cEndTime)
Return (((dEndDate - dStartDate) * 86400) - TimeToSec(cStartTime)) + TimeToSec(cEndTime)
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"
Zupan Miran
Slovenia