Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Calculate difference between multiple days

by Discipulus (Canon)
on Oct 24, 2018 at 15:45 UTC ( [id://1224597]=note: print w/replies, xml ) Need Help??


in reply to Calculate difference between multiple days

Hello, I doubt to have understood what a difference from 3 dates can be..

I just guess you want the maximum difference in a set; if so you can sort by epoch and take first and last one:

use strict; use warnings; use Date::Calc qw(:all); my @array1 = (2018,04,11,0,0,0); my @array2 = (2018,04,12,0,0,0); my @array3 = (2018,04,13,0,0,0); my @ordered = sort { Mktime(@{$a})<=> Mktime(@{$b})} \@array1,\@array2 +,\@array3; print "@$_\n" for @ordered; my $dd = Delta_Days(@{@ordered[0]}[0..2],@{@ordered[-1]}[0..2]); print "Max delta is $dd day(s)\n"; #OUTPUT 2018 4 11 0 0 0 2018 4 12 0 0 0 2018 4 13 0 0 0 Max delta is 2 day(s)

If not, please explain your question more verbosely

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Calculate difference between multiple days
by Anonymous Monk on Oct 25, 2018 at 09:59 UTC
    Hello all and thank you for your kind replies!
    I actually meant an all-against-all comparison, but I think I will go for something like this:
    #!/usr/bin/env perl use strict; use warnings; my $date_first = '2005-09-27'; my $date_second = '2019-12-22'; my $date_third = '1999-12-22'; use Time::Piece; my $date1 = localtime( $date_first ); my $date2 = localtime( $date_second ); my $date3 = localtime( $date_third ); if( $date2 > $date1 and $date2 > $date3 and $date1 > $date3) { print "correct\n"; }

    since I just needed to only compare between them and not calculate days. This works for me now, thanks again!
      if( $date2 > $date1 and $date2 > $date3 and $date1 > $date3)

      Can you spot which of these three comparisons is redundant?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1224597]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-25 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found