[Israel.pm] Date manipulations

Assaf Gordon assafgordon at gmail.com
Sun Dec 30 11:24:44 PST 2012


On 12/30/12 07:49, Gabor Szabo wrote:
>> DateTime is slow.
>> Date::Calc on the other hand, may give an incorrect answer
> Here is what Dilbert says about the subject:
> http://dilbert.com/strips/comic/2000-09-23/ :)
>

Sometimes old ways are the simplest (even if not pure Perl):

     $ date -d "2012-12-30 12pm + 10 days"
     Wed Jan  9 12:00:00 EST 2013
     $ date -d "2012-12-30 12pm - 10 days"
     Thu Dec 20 12:00:00 EST 2012

To print just the date:
     $ date -d "2012-12-30 12pm + 10 days" +%F
     2013-01-09

Or just the day:
     $ date -d "2012-12-30 12pm + 10 days" +%A
     Wednesday

The "12pm" is there to avoid leap-day related surprises.


-gordon



More information about the Perl mailing list