Novice here. Sorry and Thanks in advance. I have a future date
(ie:2013-06-09 / $fields[12])
I need to subtract today
(ie:2013-03-08)
to get the number of days remaining.
Novice here. Sorry and Thanks in advance. I have a future date
(ie:2013-06-09 / $fields[12])
I need to subtract today
(ie:2013-03-08)
to get the number of days remaining.
I'd use DateTime. If you start with the date as a string, you could use DateTime::Format::Strptime to parse it.
use DateTime qw( );
use DateTime::Format::Strptime qw( );
my $format = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%d',
time_zone => 'local',
on_error => 'croak',
);
my $ref = DateTime->today( time_zone => 'local' );
my $dt = $format->parse_datetime('2013-06-09');
my $days = $ref->delta_days($dt)->in_units('days');
print(
$dt < $ref ? "$days days ago\n" :
$dt > $ref ? "$days days from now\n" :
"today\n");
use the DateTime module:
use DateTime;
my $d1 = DateTime->new(
year => 2013,
month => 9,
day => 6
);
my $d2 = DateTime->now;
my $diff = $d2->delta_days($d1);
print $diff->delta_days, "\n"; # 182 (from 8/3/2013)