http://qs321.pair.com?node_id=724890

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Date::Manip - date differences
by dsheroh (Monsignor) on Nov 20, 2008 at 16:11 UTC
    The easiest way to do it using Date::Manip would be to grab the documentation and use something very like example #4 ("The amount of time between two dates.") to determine the difference between the two dates, then use something very like example #5 ("To determine a date a given offset from another.") to apply the calculated offset to other dates.

    The most efficient way to do it would likely be to not use Date::Manip, as detailed in the "SHOULD I USE DATE::MANIP" section of the documentation. (Although I can't tell you what would be the more efficient module to use because I tend to value "easy" over "efficient" and would just use Date::Manip despite the author's explanation of why I shouldn't.)

Re: Date::Manip - date differences
by Narveson (Chaplain) on Nov 20, 2008 at 14:54 UTC

    The requirement sounds fairly clear, so it's entirely possible that one of the brethren will come back with a solution all worked out for you.

    To improve your chances, offer a set of sample data and desired results. To improve them even more, share your first attempt at coding a solution and the output you got.

Re: Date::Manip - date differences
by Anonymous Monk on Nov 20, 2008 at 14:53 UTC

    What have you tried, after having Read The Fine Manual?

Re: Date::Manip - date differences
by cog (Parson) on Nov 20, 2008 at 16:01 UTC
    what's the easiest/most efficient way to do this?

    First, "take 2 dates and find out the number of days they differ", then "take that difference and add or subtract that number of days from a series of other dates".

Re: Date::Manip - date differences
by apl (Monsignor) on Nov 20, 2008 at 15:05 UTC
Re: Date::Manip - date differences
by barvin (Beadle) on Nov 20, 2008 at 16:20 UTC
    I believe that DateTime is the preffered module for this type of date calculations.
Re: Date::Manip - date differences
by Zoffix (Acolyte) on Oct 15, 2011 at 13:09 UTC

    While I understand the whole "teach a man to fish" point of view, I can also say that saying "RTFM" is not an acceptable answer to any question.

    I just wasted an hour reading Date::Manip docs to find how to use the module to find the difference in *days*, not in deltas as the documentation examples show.

    If you think I've learned something now, or that I am now better off than just copying someone's pre-existing code - well, think again. In the hour I've lost, I could've been finished with my project already. I very rarely manipulate dates, so the little that I've learned about the module will be well forgotten by the time I'll need it again.

    Anyway, this is the code I came up with (no idea how "efficient" it is):

    perl -MDate::Manip -wle 'print Delta_Format(DateCalc("Sept 3, 2011", "Oct 5, 2011"), 2, "%dt")'

    And if anyone cares to learn about the module, they can now go and read about those functions instead of couple score of pages about functions they'll never ever need to use!

      Agree and thanks for a workable solution to a rare problem
A reply falls below the community's threshold of quality. You may see it by logging in.