develooper Front page | perl.beginners | Postings from May 2007

Effective date grab

Thread Next
From:
Mathew Snyder
Date:
May 31, 2007 21:37
Subject:
Effective date grab
Message ID:
465FA240.4060105@yahoo.com
A while ago I had posted requesting help with a long block of code that would do
all kinds of stuff dealing with the date.  It turned out to not work despite
being technically, correct.  Instead of getting help with it, Mr. Phoenix
provided me with a block of code that did what I needed but much more concisely.
 And, more importantly, correctly.

for (1 .. 7) {
  $time -= 24*60*60;
  my @date = (localtime($time))[3 .. 5];
  push @days, (sprintf '%02d', $date[0]);
  push @months,(sprintf '%02d',$date[1] + 1);
  push @years, $date[2] + 1900;
  push @searchDate, join "-", ($date[2] + 1900), (sprintf '%02d',$date[1] + 1),
(sprintf '%02d', $date[0]);
}

This will give me a weeks worth of dates regardless of whether or not the month
flips over in the middle of the week.

What I'd like to do now is modify this or figure out a similar block of code
that will do the same only for an entire month.  The thing I see being a problem
though is that some months have 30 days, some months have 31 days and February
has 28/29 days.  This makes it pretty much impossible to just do a for loop
utilizing (1..whatever).  How can I populate an array of an entire month's worth
of dates without worrying about how many days the month has?

Mathew
-- 
Keep up with me and what I'm up to: http://theillien.blogspot.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About