On Sep 26, John Grimes said:

>Let's say I've got two dates.  The current date, and a date in the past.
>What's the scripting module that I'm going to need to compute the difference
>between the two dates?  I've gone to perl.com, but nothing seems quite
>exactly what I'm looking for...

I'm an advocate of using the STANDARD modules and a bit of brains to do
this -- I don't need Date::Calc or Date::Manip.

  use Time::Local;  # for the timelocal() function

  my $this = "11/09/1981";  # my birthday
  my $that = "04/03/1982";  # my girlfriend's birthday

  my $seconds_diff = date_to_sec($that) - date_to_sec($this);
  my $days_diff = int($seconds_diff / 86400);

  print "I am $days_diff days older than my girlfriend.\n";

  sub date_to_sec {
    # split up date, and remove leading zeroes
    my ($mon, $day, $year) = map { s/^0+//; $_ } split '/', shift;

    # return the day at 12:00 noon
    return timelocal(0,0,12, $day, $mon - 1, $year - 1900);
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to