Wow, thanks

But there still is a problem, that is semi-approx, and he wants semi-exact

use Date::Manip; my $dt1="2016080100:00:00"; my $dt2='2016123100:00:00'; my $date1 = new Date::Manip::Date; my $date2 = $date1->new_date(); $date1->parse($dt1); $date2->parse($dt2); my $delts = $date1->calc($date2,'semi'); my $delte = $date1->calc($date2,'exact'); my $delve=$delte->value(); my $delvs=$delts->value(); sub semi_exact { my $delve=shift; my @parts=split(':',$delve); my $h0=$parts[4]+$parts[3]*24+$parts[2]*7*24; my $w=sprintf('%d',$h0/(7*24)); $h0=$h0-$w*7*24; if ($w<0) {$h0=$h0*-1;} my $d=sprintf('%d',$h0/24); $h0=$h0-$d*24; my $delvse="0:0:$w:$d:$h0:$parts[5]:$parts[6]"; return $delvse; } # semi-exact my $delvse=semi_exact($delve); print 'exact :'.$delve."\n"; print 'semi-approx:'.$delvs."\n"; print 'semi-exact :'.$delvse."\n"; my $fe=DateCalc($dt1,$dt2,0); my $fse=semi_exact($fe); print 'functional semi-exact :'.$fse."\n"; exit;
output
exact :0:0:0:0:3649:0:0 semi-approx:0:0:21:5:0:0:0 semi-exact :0:0:21:5:1:0:0 functional semi-exact :0:0:21:5:1:0:0


In reply to Re^2: DateCalc using Date::Manip by huck
in thread DateCalc using Date::Manip by tsdesai

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.