Print date for the monday of the current week (in bash)
#mondaydate -dmonday +%Y%m%d#last mondaydate -dlast-monday +%Y%m%d#next mondaydate -dnext-monday +%Y%m%d#two mondays from nowdate -d'monday+14 days' +%Y%m%d#two mondays agodate -d'monday-14 days' +%Y%m%d#although, if you fancy yourself an Abraham Lincolindate -d'monday-fortnight ago' +%Y%m%d #2 weeks agodate -d'monday+fortnight' +%Y%m%d #2 weeks from now#Monday Next Yeardate -d'52+monday' +%Y%m%d#However, Monday Last Yeardate -d'52-monday' +%Y%m%d #DOES NOT WORK#you can try a day other than monday#and format this differently.
if a range is what your after you may need to do a few things
#Tuesday to Sunday#since today is monday, I'll use Tuesdayecho `date -dtuesday +%Y%m%d-``date -dnext-sunday +%Y%m%d`
which would output:
20110628-20110703
note this only works on GNU date
I have read that:
Solaris version of date, which unable to support
-d
can be resolve with replacing sunfreeware.com version of date
For those of us without GNU dates (like us OS Xers), we may have the "-v" parameter
You can then do this:
# Most recent Mondaydate -v -Mon# Output as of this writingMon Jun 24 12:35:48 EDT 2013date -v -Mon "+%Y%m%d"# Outputs20130624
This also seems to not be a problem if today is Monday, in my current case Thursday
# Today's datedate# OutputsThu Jun 27 12:41:39 EDT 2013# Most recent Thursdaydate -v -Thu# OutputsThu Jun 27 12:41:46 EDT 2013