Tuxedo
unread,May 9, 2017, 4:54:14 PM5/9/17You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hello,
Time::Piece appears to be a great toolkit for date functions including
comparing days beetween two given dates in a easy way.
Following some other examples, I found this to work:
use strict;
use warnings;
use Time::Piece;
my $date_start = '2016-05-09';
my $date_until = '2017-05-09';
my $format = '%Y-%m-%d';
my $diff = Time::Piece->strptime($date_until, $format)
- Time::Piece->strptime($date_start, $format);
print $diff / 86400;
However, as both the $date_start and $date_until placeholders will be
available in the %Y-%m-%d format already, later to be read in as result of
a
function, it appears I'm unecessarily repeating the formatting with the
Time::Piece->strptime(..., $format) parts in the above example.
How can this be constructed a bit better?
Many thanks,
Tuxedo