Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Is it possible to find out the day differece between two dates and month difference between two dates using Date::Manip module?

Thanks

  • Comment on Date Difference using Date::Manip module

Replies are listed 'Best First'.
Re: Date Difference using Date::Manip module
by GrandFather (Saint) on Apr 11, 2011 at 05:47 UTC
Re: Date Difference using Date::Manip module
by Ratazong (Monsignor) on Apr 11, 2011 at 05:45 UTC
Re: Date Difference using Date::Manip module
by perladdict (Chaplain) on Apr 11, 2011 at 09:50 UTC
    #!/usr/local/bin/perl use Time::Local; # months start at 0 # years have 1900 subtracted: ###time=timelocal($sec, $min, $hours, $day, $mon, $year) $time1=timelocal(30, 20, 18, , 2, 7, 106); $time2=timelocal(45, 15, 12, , 4, 7, 106); $time3=$time2-$time1; print "$time3 difference in seconds\n";
Re: Date Difference using Date::Manip module
by toolic (Bishop) on Apr 11, 2011 at 14:37 UTC
Re: Date Difference using Date::Manip module
by Khen1950fx (Canon) on Apr 11, 2011 at 07:46 UTC
    Date::Day makes it extremely easy:
    #!/usr/bin/perl use strict; use warnings; use Date::Day; print my $result = &day(03,11,2011), "\n", &day(04,11,2011), "\n";
      Uh... makes what extremely easy?

      Your answer seems to be only tangentially related to the question.

Re: Date Difference using Date::Manip module
by locked_user sundialsvc4 (Abbot) on Apr 11, 2011 at 15:55 UTC

    It is pretty much a “given” that, no matter what common task it is that you’re doing, someone out there on CPAN has done it .. and has done it well.   So, the first course of action in almost every case should be to first use “Super Search” here, then to go to http://search.cpan.org.

    CPAN modules are routinely accompanied by a thorough self-test suite that runs automatically on your system as part of the installation sequence.   (The module won’t install unless it first passes all of the tests, and there could be several hundred of these.)   So, by choosing the highest-level module that matches your problem most completely, you come away with a thoroughly written and tested solution that you didn’t have to write.

    Actum ne agas – do not do a thing already done.

      He already knows about CPAN. That's where the module--clearly mentioned in both the title and the body of the OP's post--lives.

      Which makes this post, like 90% of those you make, pointless, platitudinous, fatuous froth.

      So desperate are you to say something, you'll say anything, no matter how irrelevant or wrong.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.