FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Minutes calculation- RESOLVED
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Minutes calculation- RESOLVED
Posted: Mon Sep 16, 2019 08:06 PM
I have two Hour and I need the difference in minutes

sample :

access 10:45
exit 12:33

I tried with

Code (fw): Select all Collapse
nTimeFrom  := Val(Left(cTimeStart,2)+Right(cTimeStart,2))
      nTimeTo    := Val(Left(cTimeEnd,2)+Right(cTimeEnd,2))
      nMinutes1   := TimeToSec(cTimeStart)
      nMinutes2   := TimeToSec(cTimeEnd)
      nMinutes    :=  (nMinutes2-nMinutes1)


But sometimes give me a negative value
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Minutes calculation
Posted: Mon Sep 16, 2019 08:17 PM
Silvio,


// Return the absolute difference between two times in hh:mm:ss format
// in character hours, minutes and seconds (hh:mm:ss).
// TIME_DIFF( "22:40:12", "23:55:17" ) -> 01:15:05
// TIME_DIFF( "23:55:17", "22:40:12" ) -> 01:15:05

( convert to minutes if needed ) !!

Code (fw): Select all Collapse
function TIME_DIFF(cTIME1,cTIME2)
local  nTIME1, nTIME2, nDELSECS, nHRS, nMINS, nSECS, nSECS1, nSECS2

nSECS1   := (val(substr(cTIME1,1,2)) * 3600) +;
              (val(substr(cTIME1,4,2)) * 60) + (val(substr(cTIME1,7)))
nSECS2   := (val(substr(cTIME2,1,2)) * 3600) +;
              (val(substr(cTIME2,4,2)) * 60) + (val(substr(cTIME2,7)))
nDELSECS := abs(nSECS2 - nSECS1)
nHRS     := int(nDELSECS / 3600)
nMINS    := int((nDELSECS - nHRS * 3600) / 60)
nSECS    := nDELSECS - (nHRS * 3600) - (nMINS * 60)

return right("00" + ltrim(str(nHRS)),2) + ;
":" + ;
right("00" + ltrim(str(nMINS)),2) + ;
":" + ;
right("00" + ltrim(str(nSECS)),2)


regards
Uwe
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Minutes calculation
Posted: Mon Sep 16, 2019 08:28 PM

I need all to minutes because I must calculate the euro/min

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Minutes calculation
Posted: Mon Sep 16, 2019 10:04 PM

Prueba pasar las horas a minutos y operar

Saludos

Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Minutes calculation
Posted: Mon Sep 16, 2019 10:33 PM

try Val(Left(cTimeEnd,2)) * 60 + val( Right(cTimeEnd,2)) - ( Val(Left(cTimeStart,2)) * 60 + val( Right(cTimeStart,2)) )

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Minutes calculation
Posted: Mon Sep 16, 2019 11:14 PM
Prueba asi:
Code (fw): Select all Collapse
Function TotMinutos()
local cIniTime, cEndTime, nMnts1, nMnts2, nMntsTotal

cIniTime := "22:30"   
cEndTime := "06:28"   

nMnts1 := Val(Left(cIniTime,2)) * 60  + Val(Right(cIniTime,2)) 
nMnts2 := Val(Left(cEndTime,2)) * 60  + Val(Right(cEndTime,2))

if cEndTime < cIniTime
   nMnts2 := ( ( 24 + Val(Left(cEndTime,2)) ) * 60 )  + Val(Right(cEndTime,2))
endif

nMntsTotal := nMnts2 - nMnts1

Return msginfo("Hora Inicio " + cIniTime + CRLF+;
               "Hora Final  " + cEndTime + CRLF+;
               "Tot Minutos " + Transform(nMntsTotal,"99,999"), "Total Minutos")

Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Minutes calculation
Posted: Tue Sep 17, 2019 07:08 AM
Silvio,

just some small changes and You can use any format



Code (fw): Select all Collapse
MsgAlert( "      Time : 12:12:00   to   16:16:32" + CRLF + ;
                  ""  + CRLF + ;
         "      Time-format : " + TIME_DIFF("H", "12:12:00" , "16:16:32") + CRLF + ;
                 ""  + CRLF + ;
         "      Seconds > 30 are rounded to 1 minute" + CRLF + ;
                 ""  + CRLF + ;
         "      Minutes : " + ALLTRIM( STR(TIME_DIFF("M", "12:12:00" , "16:16:32") ) ), "Time-format or Minutes" )

MsgAlert( "      Time : 12:12   to   16:16" + CRLF + ;
                  ""  + CRLF + ;
         "      Time-format : " + TIME_DIFF("H", "12:12" , "16:16") + CRLF + ;
                 ""  + CRLF + ;
         "      Minutes : " + ALLTRIM( STR(TIME_DIFF("M", "12:12" , "16:16") ) ), "Time-format or Minutes" )


// --------------------------

FUNCTION TIME_DIFF(ncType, cTIME1,cTIME2)
local  nTIME1, nTIME2, nDELSECS, nHRS, nMINS, nSECS, nSECS1, nSECS2, ncValue, nRound := 0

nSECS1   := (val(substr(cTIME1,1,2)) * 3600) +;
    (val(substr(cTIME1,4,2)) * 60) + (val(substr(cTIME1,7)))
nSECS2   := (val(substr(cTIME2,1,2)) * 3600) +;
        (val(substr(cTIME2,4,2)) * 60) + (val(substr(cTIME2,7)))
nDELSECS := abs(nSECS2 - nSECS1)
nHRS     := int(nDELSECS / 3600)
nMINS    := int((nDELSECS - nHRS * 3600) / 60)
nSECS    := nDELSECS - (nHRS * 3600) - (nMINS * 60)

IF ncType = "H"
    IF LEN( cTIME1 ) > 5 
        ncValue := right("00" + ltrim(str(nHRS)),2) + ;
        ":" + right("00" + ltrim(str(nMINS)),2) + ;
        ":" + right("00" + ltrim(str(nSECS)),2)
    ELSE
        ncValue := right("00" + ltrim(str(nHRS)),2) + ;
        ":" + right("00" + ltrim(str(nMINS)),2) 
    ENDIF
ELSE
    IF nSECS > 30 .and. LEN( cTIME1 ) > 5
        ncValue := int(nHRS * 60 + nMINS + 1)
    ELSE
           ncValue := int(nHRS * 60 + nMINS)
    ENDIF
ENDIF

RETURN ncValue


regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Minutes calculation
Posted: Tue Sep 17, 2019 03:21 PM

thanks resolved

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion