Reputation: 1259
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. Suppose
on saturday i made this file
weekly_user1_Jul-13-2013.sql
I ned to get that name in script which i run daily. so for script running on saturday i need to get todays date , buif its on sunday then i need to get last saturday date.
how can i do that
Upvotes: 8
Views: 8444
Reputation: 4971
In python script:
from datetime import date
from datetime import timedelta
today = date.today()
last_saturday = today - timedelta(days= (today.weekday() - 5) % 7)
Upvotes: 2
Reputation: 798606
$ date +"%b-%d-%Y" -d "last saturday"
Jul-13-2013
Upvotes: 24