Hello Everyone, I have this code misbehaving in one of my scripts, I have a var containing the sequential number of the day for the year and I am suppose to get the regular date for that day and its weekday. If I set the day to 273 I get back 2008/09/31 which is not a proper date. can you help me understand why? .................
syy=2008 newstart=272 perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $my +time = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec, +$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime); $yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX + qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday nu +mber; $weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1 +, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pp +pp newstart=273 perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $my +time = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec, +$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime); $yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX + qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday nu +mber; $weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1 +, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pp +pp newstart=274 perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $my +time = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec, +$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime); $yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX + qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday nu +mber; $weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1 +, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pp +pp the contents of pppp: 2008/09/30 Tuesday 2008/09/31 Wednesday 2008/10/01 Wednesday
Thanks for your help.

In reply to Number of day in the year to proper date by gio001

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.