Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Hash Math

by Cristoforo (Curate)
on Jun 10, 2014 at 02:16 UTC ( [id://1089376]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash Math
in thread Hash Math

Here is a way to get the difference between the dates in days from an array of dates. (Note that the dates are sorted. If your array isn't sorted you would have some negative differences).
#!/usr/bin/perl use strict; use warnings; use Time::Piece; my @date = ( '2014-06-01', '2014-06-02', '2014-06-03', '2014-06-04' ); for my $i (0 .. $#date-1) { my $d1 = Time::Piece->strptime($date[$i], '%Y-%m-%d'); for my $j ($i+1 .. $#date) { my $d2 = Time::Piece->strptime($date[$j], '%Y-%m-%d'); my $diff = $d2 - $d1; print $d1->ymd, " and ", $d2->ymd, " is ", $diff->days, "\n"; } }
Prints
2014-06-01 and 2014-06-02 is 1 2014-06-01 and 2014-06-03 is 2 2014-06-01 and 2014-06-04 is 3 2014-06-02 and 2014-06-03 is 1 2014-06-02 and 2014-06-04 is 2 2014-06-03 and 2014-06-04 is 1

Log In?
Username:
Password:

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

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

    No recent polls found