Oh mighty Perl Monks, answer of your wisdom, I entreat.

I have a subroutine whose original intent was to mung the date so as to name a file based on whatever the date is of the Friday of the given week. So that, for example, if it's Wednesday 10/4/2000, the file gets gets titled 10_6_2000.html (with the idea that it's appended to after that).

It worked fine up to some unspecified time ago (I only found out it was broken when one of my users reported a different problem entirely). Now it's telling me that Friday is 9/28/2000. Here's the code in question:

$now = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$rest) = localtime($now); if ($wday !=4) { $dow = $wday; if ($dow < 4) { $dow += 7; } $then = (($dow - 4) * 60 * 60 * 24); } ($sec,$min,$hour,$mday,$mon,$year,$rest) = localtime($now - $then); $mon=$mon+1; $year=$year+1900;

Why's it not working? Should it have ever worked??

Thanks for your attention.

    - Muse


In reply to Date munging suddenly broken by motomuse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.