in reply to difference between 2 dates

Try the nifty new Time::Piece module. It makes this stuff easy.
#!/usr/bin/perl -wT use strict; use Time::Piece; my $date1 = "2000-11-24 03:23:45"; my $date2 = "2001-01-24 05:45:00"; my $format = "%Y-%m-%d %T"; my $diff = abs (Time::Piece->strptime( $date1, $format ) - Time::Piece->strptime( $date2, $format )); print "There are " . $diff->minutes . " minutes between $date1 and $da +te2\n"; __END__ There are 87981.25 minutes between 2000-11-24 03:23:45 and 2001-01-24 +05:45:00

-Blake

Replies are listed 'Best First'.
Re: Re: difference between 2 dates
by steves (Curate) on Mar 06, 2002 at 13:42 UTC

    I like this ... I didn't realize until now that strptime was set up to return a Time::Piece object and that you could directly subtract one Time::Piece object from another. Very nice. Monk discussion once again proves to be educational.

      Also notice that the subtraction returns a Time::Seconds object rather than a simple integer. This trivialized the "in minutes" requirement, and makes more complicated calculations less error prone.

      -Blake