How to find out the date of the last Saturday in Linux shell script or python?

后端 未结 3 1882
臣服心动
臣服心动 2021-01-02 23:38

I have python script which i need to run daily for backups. Now i need to find the date of last saturday because i need that in my script to get the backups i did on last sa

3条回答
  •  粉色の甜心
    2021-01-03 00:11

    In python script:

    from datetime import date
    from datetime import timedelta
    today = date.today()
    last_saturday = today - timedelta(days= (today.weekday() - 5) % 7)
    

提交回复
热议问题