Skip to content Skip to sidebar Skip to footer

How To Find Out The Date Of The Last Saturday In Linux Shell Script Or Python?

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 saturdy.

Solution 1:

$ date +"%b-%d-%Y" -d "last saturday"
Jul-13-2013

Solution 2:

In python script:

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

Solution 3:

On Mac OS it would be:

$ date -v -sat +"%b-%d-%Y"
Mar-28-2015

Post a Comment for "How To Find Out The Date Of The Last Saturday In Linux Shell Script Or Python?"