Hello Monks,

i have a question here regarding to calculate the minutes difference between two dates. i have written a code here, but i know it's not very accurate, because i assume every month is 30 days and 365 days in a year (it goes very wrong when calculate the dates for example: 2007-12-31 16:50:00;2008-1-1 04:24:00;), anyone know there is a perl module can calculate the accurate minuets between two dates ?

#!/usr/bin/perl use strict; use warnings; #Using perl package use Date::Calc qw(Delta_YMDHMS); use Date::Calc qw(Add_Delta_DHMS); #subroutine: rounding no sub round($); while (<TEMP>) { my @line=split(";"); my @start_time=($line[3]=~/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/); + #parsing the start time my @stop_time=($line[4]=~/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/); + #parsing the stop time my @diff=Delta_YMDHMS(@start_time,@stop_time); + #calculate diff in YMDHMS my($yyyy,$m,$d,$hh,$mm,$ss)=@diff; $min_diff=($yyyy*365*24*60+$m*30*24*60+$d*24*60+$hh*60+$mm*1+$ss*0); + #convert to mins $interval=round($min_diff/15); + #get the interval print "minutes difference between two dates are: $min_diff"; } sub round($) { my($number) = shift; return int($number + .5); }
thanks,

In reply to Find minutes difference between two dates by hujunsimon

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.