• Simple Time::Piece days comparison

    From Tuxedo@21:1/5 to All on Tue May 9 22:51:09 2017
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)