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

后端 未结 9 993
深忆病人
深忆病人 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:31

    You could use Date::Manip, which has a Date_GetPrev function and understands "Monday"

    $ perl -MDate::Manip -le 'print UnixDate(Date_GetPrev(shift, "Monday", 0), "%Y-%m-%d")' 2011-06-11
    2011-06-06
    

提交回复
热议问题