Using Date::Manip

Here’s a quick code sample to loop over the dates in a range with Perl’s Date::Manip. The documentation is voluminous and yet I found it difficult to understand; for people who learn best by example, here goes:

use Date::Manip;

#                    Y M W DDD MS?    'base'       'start'      'end' 
#@dates = ParseRecur("0:0:0:1*1:0:0","12/1/08","12/1/08","1/7/09") ;
@dates = ParseRecur("0:0:0:1*1:0:0","1 month ago", "1 month ago", "today");

foreach my $date ( @dates )   {
        #printf qq|%sn|, &UnixDate($date, "%B %d, %Y");
        printf qq|%sn|, &UnixDate($date, "%D");
}

The date formats (%B, %d, %D, etc.) are consistent with those documented in the date manpage.

Leave a Reply

Your email address will not be published. Required fields are marked *