I don't have a 'semi-exact' mode in Date::Manip... but what you're really saying is: convert an exact delta to a semi-approximate one.

This is of course different from coming up with an semi-approximate delta from two dates (which is what I was doing... I should have noticed that it wasn't exactly what the OP was doing, but I got ahead of myself after noticing I couldn't use 'semi' mode in the older DateCalc).

In any case, you can do the following:

use Date::Manip; my $dt1='2016080100:00:00'; my $dt2='2016123100:00:00'; my $exact= DateCalc($dt1,$dt2); my $semi = DateCalc($dt1,$dt2,'semi'); print "Exact : $exact\n"; print "Semi : $semi\n"; my $delta = ParseDateDelta($exact,'semi'); print "Exact->Semi: $delta\n"; print "\n"; use Date::Manip::Date; my $date1 = new Date::Manip::Date; my $date2 = $date1->new_date(); $date1->parse($dt1); $date2->parse($dt2); my $delt_x = $date1->calc($date2); my $delt_s = $date1->calc($date2,'semi'); my $val = $delt_x->value(); print "New Exact : $val\n"; $val = $delt_s->value(); print "New Semi : $val\n"; $delt_x->convert('semi'); $val = $delt_x->value(); print "New Ex->Se: $val\n";

which yields:

Exact : 0:0:0:0:3649:0:0 Semi : 0:0:21:5:0:0:0 Exact->Semi: 0:0:21:5:1:0:0 New Exact : 0:0:0:0:3649:0:0 New Semi : 0:0:21:5:0:0:0 New Ex->Se: 0:0:21:5:1:0:0

So you can see how to convert an exact delta to a semi-approximate one using either the old or new interfaces.


In reply to Re^3: DateCalc using Date::Manip by SBECK
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.