in reply to Getting previous dates from the current date

Yes, there are modules to do that directly and you should use them.

However, a small "proof of concept" won't hurt anyone:

my $date = '2005-03-29'; my $d = ...; # anyone knows of a direct way to do this? for (1, 7, 14) { my $d = $d - $_ * 60 * 60 * 24; printf ("$_ days ago: %04d-%02d-%02d",(localtime($d))[5,4,3]); }
Warning: The code presented doesn't consider daylight saving times changes.

Replies are listed 'Best First'.
Re^2: Getting previous dates from the current date
by Smylers (Pilgrim) on Mar 29, 2005 at 17:27 UTC
    However, a small "proof of concept" won't hurt anyone

    Yes it will — it will hurt people who see your code and think that it works! Didn't the clocks change in Portugal on Sunday as well? You can't assume that days will have exactly 24 hours in them.

    Smylers

      Well, I do say it's a proof of concept, and I even underlined it to note that...

      But you are, of course, correct. People look at code and copy-paste it without looking at nothing else, so... I hope they will at least notice the bold warning at the bottom, which was just placed there.