Like Coyote said, use
Date::Manip - it'a a darn good module and it will do alot more than what you would probably expect.
Now though - to get a list of the first Monday in every month starting Jan 2001 - Dec 2001, I used the following snippet of code and got every single one:
#!/usr/bin/perl -w
use strict;
use Date::Manip;
my $base = "2000123123:59:59";
my $start = "2001010100:00:00";
my $stop = "2001123123:59:59";
my $syntax = "0:1*1:1:0:0:0";
my @dates = &ParseRecur($syntax,$base,$start,$stop);
foreach my $day (@dates)
{
print "\$day is [$day]\n";
}
This prints out:
$day is [2001010100:00:00]
$day is [2001020500:00:00]
$day is [2001030500:00:00]
$day is [2001040200:00:00]
$day is [2001050700:00:00]
$day is [2001060400:00:00]
$day is [2001070200:00:00]
$day is [2001080600:00:00]
$day is [2001090300:00:00]
$day is [2001100100:00:00]
$day is [2001110500:00:00]
$day is [2001120300:00:00]
And yes, I did verify the dates :)
Update:You may want to use
substr($day,0,8); to get the first 8 characters which is the date - anything after that is the time
- oakley
Embracing insanity - one twitch at a time >:)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.