How to get the date of Monday and Sunday in a week for a date?
This gives date for 'last' monday:
date -dlast-monday +%Y%m%d
I want to pass a date as parameter to find the Monday and Sunday for that week. Basically, I want to get Sunday and Monday for a week, for ANY date, NOT only for last monday.
Try this:
export day=2013-10-01
date -d "$day -$(date -d $day +%w) days"
This will always print the Sunday before the given date (or the date itself).
date -d "$day -$(date -d $day +%u) days"
This will always print the Sunday before the given date (and never the date itself).
For Mondays you need to add + 1 day
:
date -d "$day -$(date -d $day +%u) days + 1 day"
You should also consider what Monday or Sunday you want to get (this wasn't quite clear) for which date. This also depends on whether you consider the Sunday the first or the last day of the week.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With