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.) | [reply] |
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.
| [reply] |
What have you tried, after having Read The Fine Manual?
| [reply] |
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". | [reply] |
| [reply] |
I believe that DateTime is the preffered module for this type of date calculations. | [reply] |
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!
| [reply] [d/l] |
Agree and thanks for a workable solution to a rare problem
| [reply] |