How can I calculate the number of days between two dates in Perl?

前端 未结 7 2309
长发绾君心
长发绾君心 2020-12-05 19:05

I want to calculate (using the default Perl installation only) the number of days between two dates. The format of both the dates are like so 04-MAY-09. (DD-MMM-YY)

I

7条回答
  •  伪装坚强ぢ
    2020-12-05 19:44

    Time::ParseDate will handle that format just fine:

    use Time::ParseDate qw(parsedate);
    
    $d1="04-MAR-09";
    $d2="06-MAR-09";
    
    printf "%d days difference\n", (parsedate($d2) - parsedate($d1)) / (60 * 60 * 24);
    

提交回复
热议问题