http://www.perlmonks.org?node_id=162721

BUU has asked for the wisdom of the Perl Monks concerning the following question:

What im trying to do, is find the difference between to dates, one in a mysql timestamp format, the other in the localtime format, in the form of seconds:minutes:hours etc. I tried to use Class::Date, but all i could get it to do was give me the number of seconds between the dates, which when i tried to get it to give me a nice string, always gave me something like '1970 january 1..', b/c it adds the seconds onto that date or something like that. None of the other modules on cpan seemed to do what i wanted, they all just appeared to be methods for deterimining a specific date in time. Anyone know of a good module or something? This is the code i came up with:
my ($i,$d,@posttime,@difference,@t); my $posttime=shift; my @mytime=(localtime)[0..5]; $mytime[5]+=1900; $mytime[4]+=1; for(my $i=0;$i<scalar @t;$i++){next if $i==0;$mytime[$i]=(length $ +mytime[$i]==1)?'0'.$mytime[$i]:$mytime[$i]}; unshift @posttime,(substr "$posttime",0,4); for($i=4;$i<14;$i+=2){unshift @posttime,(substr "$posttime",$i,2); +} if(($mytime[0]-$posttime[0])<0){$mytime[1]--;$mytime[0]+=60;} $difference[0]=($mytime[0]-$posttime[0]); if(($mytime[1]-$posttime[1])<0){$mytime[2]--;$mytime[1]+=60;} $difference[1]=($mytime[1]-$posttime[1]); if(($mytime[2]-$posttime[2])<0){$mytime[3]--;$mytime[2]+=24;} $difference[2]=($mytime[2]-$posttime[2]); if(($mytime[3]-$posttime[3])<0){$mytime[4]--;$mytime[3]+=31;} $difference[3]=($mytime[3]-$posttime[3]); if(($mytime[4]-$posttime[4])<0){$mytime[5]--;$mytime[4]+=12;} $difference[4]=($mytime[4]-$posttime[4]); $difference[5]=($mytime[5]-$posttime[5]); $i=0;$d=''; my @englishtime=('second(s)','minute(s)','hour(s)','day(s)','month +(s)','year(s)'); #for(@difference){$d.="$_ $mytimeime[$i] ";$i++;} $d="[$difference[0]s:$difference[1]m:$difference[2]h - $difference +[3]d/$difference[4]m/$difference[5]y]"; return $d;
I know its incredibly kludgy and barely runs under use strict, which is mostly why im looking for a good module to use.