FoxPro/Visual FoxPro - Restar dos horas

 
Vista:
sin imagen de perfil

Restar dos horas

Publicado por Daniel Giménez (2 intervenciones) el 24/05/2006 19:00:05
como hacer para restar dos horas en formato HH:MM:SS (hora , minuto y segundo)
Ej: 18:25:00 - 17:55:00 que me de como resultado 00:30:00 (30 minutos)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Restar dos horas

Publicado por atak (12 intervenciones) el 24/05/2006 22:14:42
Hola

deberias hacerlo con tratamiento de cadenas ....

hice algo como para esto :

10:20PM a 01:00AM hacer la diferencia
>> el resultado es en HORAS
Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
***  MODULO de DIFERENCIAS de HORAS
***
***  caso que  sea   AM  y  AM
IF (thisformset.form1.tipocron1.am.Value=1 AND thisformset.form1.tipocron2.am.Value=1) then
	diferencia=60*(VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2))-VAL(SUBSTR(thisformset.form1.txtci.Value,1,2)))-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))
	thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
ENDIF
***
***  caso que  sea   AM  y  PM
IF (thisformset.form1.tipocron1.am.Value=1 AND thisformset.form1.tipocron2.pm.Value=1) then
    IF VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2))=12 THEN
        diferencia=60*(12-VAL(SUBSTR(thisformset.form1.txtci.Value,1,2)))-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))
        thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
    ELSE
        diferencia=60*(12-VAL(SUBSTR(thisformset.form1.txtci.Value,1,2))+VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2)))-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))
        thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
    ENDIF
ENDIF
***
***  caso que  sea   PM  y  PM
IF(thisformset.form1.tipocron1.pm.Value=1 AND thisformset.form1.tipocron2.pm.Value=1) then
    IF (VAL(SUBSTR(thisformset.form1.txtci.Value,1,2))=12 AND VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2))=12) THEN
        diferencia=VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))- VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))
        thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
 
    ELSE
        IF (VAL(SUBSTR(thisformset.form1.txtci.Value,1,2))=12) then
            diferencia=(60-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2)))+60*(VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2))-1)+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))
            thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
        ELSE
            diferencia=60*(VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2))-VAL(SUBSTR(thisformset.form1.txtci.Value,1,2)))+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))
            thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
        ENDIF
    ENDIF
 
ENDIF
***
*** caso que sea PM  y PM
IF(thisformset.form1.tipocron1.pm.Value=1 AND thisformset.form1.tipocron2.am.Value=1) then
    diferencia=60*(12-VAL(SUBSTR(thisformset.form1.txtci.Value,1,2))+VAL(SUBSTR(thisformset.form1.txtcf.Value,1,2)))+VAL(SUBSTR(thisformset.form1.txtcf.Value,3,2))-VAL(SUBSTR(thisformset.form1.txtci.Value,3,2))
    thisformset.form1.txthrs2.Value=ROUND(diferencia/60,2)
ENDIF
thisformset.Refresh

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Restar dos horas

Publicado por Ernesto Hernandez (4623 intervenciones) el 25/05/2006 20:27:27
? Diferencia_DHMS(DATETIME(2000,3,1,12,10,05),DATETIME())

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FUNCTION Diferencia_DHMS(ttIni,ttFin)
  LOCAL ln, lnDia, lnHor, lnMin, lnSeg
  IF EMPTY(ttFin)
    ttFin = DATETIME()
  ENDIF
  ln = ttFin - ttIni
  lnSeg = MOD(ln,60)
  ln = INT(ln/60)
  lnMin = MOD(ln,60)
  ln = INT(ln/60)
  lnHor = MOD(ln,24)
  lnDia = INT(ln/24)
  RETURN ALLTRIM(STR(lnDia))+ " días, "+ ;
    TRANSFORM(lnHor, "@L 99")+ " horas, "+ ;
    TRANSFORM(lnMin, "@L 99")+ " minutos, "+ ;
    TRANSFORM(lnSeg, "@L 99")+ " segundos"
ENDFUNC

Espero te sirva

Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Restar dos horas

Publicado por Delia Peñaherrera (1 intervención) el 01/06/2019 15:15:03
Gracias, por este código, fácil y si me funciono para las fechas de nacimientos de bebes recién nacidos, gracias, gracias, gracias. mil bendiciones.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Restar dos horas

Publicado por jose (16 intervenciones) el 13/06/2006 20:56:02
mas facil:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
FUNCTION Minutos_Entre
Para x1, x2
If x1>=x2
 RETURN 0
EndIf
If Empty(x1) Or Empty(x2)
 RETURN 0
EndIf
x_Hora=x1
x_Rt=0
Do While x_Hora<x2
 x_Rt=x_Rt+1
 x_Ho=Left(x_Hora,2)
 x_Mi=Right('00'+Alltrim(Str(Val(Right(x_Hora,2))+1)),2)
 If x_Mi='60'
  x_Mi='00'
  x_Ho=Right('00'+Alltrim(Str(Val(x_Ho)+1)),2)
  If x_Ho='24'
   x_Ho='00'
  EndIf
 EndIf
 x_Hora=x_Ho+':'+x_Mi
EndDo
RETURN (x_Rt)

USO :

1
2
3
xHini = '08:10'
xHfin = '18:30'
xMinutos = Minutos_Entre(xHini,xHfin)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 115
Bronce
Ha mantenido su posición en FoxPro/Visual FoxPro (en relación al último mes)
Gráfica de FoxPro/Visual FoxPro

Restar dos horas

Publicado por Luis (42 intervenciones) el 06/06/2019 14:34:40
Deberías buscar otras alternativas.Yo también tuve esa inquietud y pude conseguir la solución en https://visualfoxprogram.blogspot.com/
y me pareció bueno el programa que calcula la diferencia entre horas
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar