bgroper has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks
I have a table of dated transactions, and I'm needing to detect any transactions dated more than 2 months into the future.
The following proof-of-conecpt code snippet is my attempt to achieve this result.
The $date variable will be filled using "SELECT date FROM table ORDER BY date DESC LIMIT 1"
The PoC seems to work, BUT can any monks help me do this a-better-way ?
TIA's for any tips or clues.
#!/usr/bin/perl use strict; use warnings; use DateTime; my $date = DateTime->new( time_zone => "UTC", year => 2019, month => 8, day => 10, ); my $now = DateTime->now; my $delta = $now - $date; my $months = $delta->{'months'}; my $days = $delta->{'days'}; print "Delta = $months months, and $days days\n"; print "*** Alert ***\n" if ($months < -2); exit(); __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Months between dates ?
by shadowsong (Pilgrim) on Jun 10, 2019 at 08:04 UTC | |
by bgroper (Novice) on Jun 10, 2019 at 09:12 UTC | |
|
Re: Months between dates ?
by haukex (Archbishop) on Jun 10, 2019 at 07:38 UTC | |
by bgroper (Novice) on Jun 10, 2019 at 09:18 UTC | |
|
Re: Months between dates ?
by hippo (Archbishop) on Jun 10, 2019 at 10:13 UTC | |
|
Re: Months between dates ?
by thanos1983 (Parson) on Jun 10, 2019 at 11:00 UTC |