Minutes calculation- RESOLVED

Minutes calculation- RESOLVED

Postby Silvio.Falconi » Mon Sep 16, 2019 8:06 pm

I have two Hour and I need the difference in minutes

sample :

access 10:45
exit 12:33

I tried with

Code: Select all  Expand view  RUN

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.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: Minutes calculation

Postby ukoenig » Mon Sep 16, 2019 8: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: Select all  Expand view  RUN

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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Minutes calculation

Postby Silvio.Falconi » Mon Sep 16, 2019 8: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: Minutes calculation

Postby horacio » Mon Sep 16, 2019 10:04 pm

Prueba pasar las horas a minutos y operar

Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Minutes calculation

Postby ADutheil » 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
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Minutes calculation

Postby FranciscoA » Mon Sep 16, 2019 11:14 pm

Prueba asi:
Code: Select all  Expand view  RUN
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
User avatar
FranciscoA
 
Posts: 2159
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Minutes calculation

Postby ukoenig » Tue Sep 17, 2019 7:08 am

Silvio,

just some small changes and You can use any format

Image

Code: Select all  Expand view  RUN

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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Minutes calculation

Postby Silvio.Falconi » Tue Sep 17, 2019 3:21 pm

thanks resolved
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests