Date calculation using GNU date

Using the GNU date command line utility, I know:

  • how to substract 3 days from any given date:
    date -d "20110405 -3 days" "+%Y%m%d"
    20110402

  • how to get the last Friday from today:
    date -d "last friday" "+%Y%m%d"
    20110408

But I don't know how to get the last Friday from any given date:
date -d "20110405 last friday" "+%Y%m%d"
Simply returns the given date:
20110405

Any ideas on how to do this? If a one-liner is not possible a few lines of script would also be helpful.

11
задан Ponytech 13 April 2011 в 20:48
поделиться