[Perl] Sobre fechas y horas

Gunnar Wolf gwolf@campus.iztacala.unam.mx
Tue, 30 Apr 2002 16:31:45 -0600 (CST)


> =BFAlguien tiene alguna rutina que le permita calcular el tiempo
> transcurrido entre una fecha y otra?
> Mi problema es que quiero calcular el numero de horas (dias, etc)
> transcurridos entre dos fechas:
>
> 4/23/2002 11:23:20 AM  y 4/23/2002 7:19:34 PM

As=F3mate al m=F3dulo Date::Calc, es una maravilla. Te copio de su
documentaci=F3n:

       o "($Dd,$Dh,$Dm,$Ds) =3D Delta_DHMS($year1,$month1,$day1,
         $hour1,$min1,$sec1, $year2,$month2,$day2,
         $hour2,$min2,$sec2);"

         This function returns the difference in days, hours,
         minutes and seconds between the two given dates with
         times.

         All four return values will be positive if the two dates
         are in chronological order, i.e., if date #1 comes
         chronologically BEFORE date #2, and negative (in all
         four return values!) if the order of the two dates is
         reversed.

         This is so that the two functions ""Delta_DHMS()"" and
         ""Add_Delta_DHMS()"" (description see further below) are
         complementary, i.e., mutually inverse:

           Add_Delta_DHMS(@date1,@time1, Delta_DHMS(@date1,@time1, @date2,@=
time2))

         yields ""(@date2,@time2)"" again, whereas

           Add_Delta_DHMS(@date2,@time2,
               map(-$_, Delta_DHMS(@date1,@time1, @date2,@time2)))

         yields ""(@date1,@time1)"", and

           Delta_DHMS(@date1,@time1, Add_Delta_DHMS(@date1,@time1, @delta))

         yields "@delta" again.

         The result is zero (in all four return values) if the
         two dates and times are identical.



--=20
Gunnar Wolf - gwolf@campus.iztacala.unam.mx - (+52-55)5623-1118
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973  F800 D80E F35A 8BB5 27AF