Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found