sachin bhomale
sachin bhomale

Reputation: 61

bash shell script for last-week dates

I am writing shell where I am going to need dates from last week irrespective of the day I am running on. I tried below but those are somehow failing. Can you please help.

date --date='last Monday'
date --date='last week + last Thursday'
date --date='last week + last Monday'

Thanks

Upvotes: 0

Views: 9103

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74605

Define on what day your week ends, and then work backwards from there. For example, assuming that your week ends on Sunday, then you can get all the dates from the previous week by doing:

saturday=$(date -d 'last Sunday - 1 day')
friday=$(date -d 'last Sunday - 2 days')
# etc.

Upvotes: 6

Related Questions