Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Find maximum (Activity) date from array hash.

by hippo (Bishop)
on Jun 02, 2020 at 20:27 UTC ( [id://11117610]=note: print w/replies, xml ) Need Help??


in reply to Find maximum (Activity) date from array hash.

You can use Time::Piece to perform the date comparisons. Then it's just a matter of choosing a sensible initial value to compare against. You could use whatever is first in your array but I've chosen to use the epoch here:

use strict; use warnings; use Test::More tests => 1; use Time::Piece; my @aoh = ( { 'Name' => 'First Segment', 'Balance' => '183.57', 'days' => 0, 'First Date' => '12/02/2020', 'payment' => 0, 'Activity Date' => '07/05/2020', 'Total Commission' => 0, }, { 'Name' => 'Discontinue Segment', 'Balance' => '67.14', 'days' => 3, 'First Date' => '17/02/2020', 'payment' => 0, 'Activity Date' => '27/03/2020', 'Total Commission' => 0.12, }, { 'Name' => 'Last Segment', 'Balance' => '12.56', 'days' => 7, 'First Date' => '19/03/2020', 'payment' => 0, 'Activity Date' => '21/04/2020', 'Total Commission' => 0, } ); my $maxdate = localtime (0); for my $hr (@aoh) { my $date = Time::Piece->strptime ($hr->{'Activity Date'}, '%d/%m/% +Y'); $maxdate = $date if $date > $maxdate; } is $maxdate->dmy ('/'), '07/05/2020';

Replies are listed 'Best First'.
Re^2: Find maximum (Activity) date from array hash.
by Sami_R (Sexton) on Jun 02, 2020 at 23:36 UTC

    Thank you hippo.

    Solution is simple and elegant! Thank you so much

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found