In Perl how to find the date of the previous Monday for a given date?

后端 未结 9 1026
深忆病人
深忆病人 2020-12-11 03:48

I am looking for a Perl script which can give me the last Monday for any specified date.

e.g. For date 2011-06-11, the script should return 2011-06-06

9条回答
  •  感情败类
    2020-12-11 04:23

    In the spirit of Perl, There Is More Than One Way To Do It.

    use Modern::Perl;
    use Date::Calc qw/Day_of_Week/;
    my $date = '2011/6/11';
    my @fields = split /\//, $date;
    my @new_date = Add_Delta_Days( @fields , 1 - Day_of_Week( @fields ) );
    say join "/", @new_date;
    

提交回复
热议问题