Minutes calculation- RESOLVED

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Minutes calculation- RESOLVED

Post by Silvio.Falconi »

I have two Hour and I need the difference in minutes

sample :

access 10:45
exit 12:33

I tried with

Code: Select all

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
Last edited by Silvio.Falconi on Tue Sep 17, 2019 7:04 pm, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Minutes calculation

Post by ukoenig »

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: Select all

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
Last edited by ukoenig on Mon Sep 16, 2019 8:41 pm, edited 1 time in total.
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.
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Minutes calculation

Post by Silvio.Falconi »

I need all to minutes because I must calculate the euro/min
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
horacio
Posts: 1270
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Minutes calculation

Post by horacio »

Prueba pasar las horas a minutos y operar

Saludos
ADutheil
Posts: 352
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Minutes calculation

Post by ADutheil »

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 BCC 5.82 MinGW 4.5.2 MSVS 10
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Minutes calculation

Post by FranciscoA »

Prueba asi:

Code: Select all

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.

Fwxh1204-MySql-TMySql
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Minutes calculation

Post by ukoenig »

Silvio,

just some small changes and You can use any format

Image

Code: Select all

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 :D
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.
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Minutes calculation

Post by Silvio.Falconi »

thanks resolved
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply