Looking for a method to convert the week of a year to Sunday's date. I have a data file that consists of issues experienced on a day to day basis. I convert these dates to "Week of Year" so I can report on the top 5 issues experienced per week. Once I tally up the data by week, I need to convert the week number back to a user readable date dd/mm/yy (sunday). Thanks to help in chat, I have this so far. This successfully prints out the top five issues by week, but, again, I need the Week Number converted back.
foreach my $week (sort keys %IssuesByWeek) { print "$week:\n\t",join ("\n\t", map{"$_ => $IssuesByWeek{$wee +k}{$_}" } (sort {$IssuesByWeek{$week}{$b} <=> $IssuesByWeek{$week}{$a +} } keys %{$IssuesB yWeek{$week}} )[0..4]),"\n" }
05.05:
        ISSUE ABC => 72
        ISSUE CBA => 39
        ISSUE BBA => 37
        ISSUE ABB => 24
        ISSUE BCA => 19
I want that instead to display:
01/23/05:
        ISSUE ABC => 72
        ISSUE CBA => 39
        ISSUE BBA => 37
        ISSUE ABB => 24
        ISSUE BCA => 19
I have Date::Manip installed already if that's needed. I see how to use it to get Week of Year, but not how to convert back. <update> Thanks all for the suggestions and code. This is how I ended up doing it and have NO idea why it works. I'll definetly be converting over to one of these.
foreach $date (reverse sort keys %IssuesByWeek) { $counter++; next if $counter>4; #Only want the most recent couple weeks ($year, $week) = split(/\./,$date); $time_t = POSIX::mktime(0,0,0,0,0,$year); #turn year to numbe +r of seconds since 1970 $secs = (604800*($week-1)+(2*24*60*60)) + $time_t; #add number + of seconds since year started some reason i kept ending up on Friday + when just multiplying the year by the week in seconds @date = POSIX::gmtime($secs); #turn seconds back to date $date[4]++; #because returned month is numbers of months since + jan ie jan is 0 $date[4] = "0".$date[4] if ($date[4]<10); $date[3] = "0".$date[3] if ($date[3]<10); $newdate = "$date[4]\/$date[3]\/$year";

In reply to Convert Week Of Year to Date by ear

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.