Using Date::Manip

In: Uncategorized

7 Jan 2009

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|%s\n|, &UnixDate($date, "%B %d, %Y");
        printf qq|%s\n|, &UnixDate($date, "%D");
}

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

Related posts:

  1. W3C Time Format and strftime
  2. Listing RPM Contents
  3. On Time
  4. Changing a Cookie’s Domain in Rails

Comment Form

On Other Sites

  • i5junkies: Thanks for this posting. It helped me fix the problem and running. GREAT post!!! [...]
  • emeka: i accidentally unscred all the screws and flipped my laptop now i dont know which screw goes where p [...]
  • Erik: Hey Matt! I came across your blog after seeing you had posted a link to our older website. I know t [...]
  • mot: haha - thats all i could say... thanks [...]
  • Motorola Phones - The RadioReference.com Forums: [...] Have a look at this page: Direct Talk Compatible Phones | Matt's Blog [...] [...]