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.

In reply to Date difference? by BUU

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.