ear has asked for the wisdom of the Perl Monks concerning the following question:
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 => 19I want that instead to display:
01/23/05: ISSUE ABC => 72 ISSUE CBA => 39 ISSUE BBA => 37 ISSUE ABB => 24 ISSUE BCA => 19I 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";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Convert Week Of Year to Date
by fglock (Vicar) on Feb 01, 2005 at 17:14 UTC | |
Re: Convert Week Of Year to Date
by bgreenlee (Friar) on Feb 01, 2005 at 17:10 UTC | |
Re: Convert Week Of Year to Date
by davido (Cardinal) on Feb 01, 2005 at 17:32 UTC | |
Re: Convert Week Of Year to Date
by demerphq (Chancellor) on Feb 01, 2005 at 18:16 UTC | |
by ear (Acolyte) on Feb 01, 2005 at 18:54 UTC | |
by K_M_McMahon (Hermit) on Feb 01, 2005 at 18:58 UTC | |
by dragonchild (Archbishop) on Feb 01, 2005 at 18:58 UTC | |
Re: Convert Week Of Year to Date
by Limbic~Region (Chancellor) on Feb 01, 2005 at 19:17 UTC | |
Re: Convert Week Of Year to Date
by dragonchild (Archbishop) on Feb 01, 2005 at 18:56 UTC |