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 ?
thanks,#!/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); }
In reply to Find minutes difference between two dates by hujunsimon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |