Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Get date of Monday two weeks ago from particular date using GNU date

I understand the command date -d 'last-monday - 14 days' +%Y%m%d will print the Monday two weeks ago from "Today's date". I need a way to test this for different dates and see the result. Almost like I need to mention the date command to do calculations off a relative date.

I need something to test with different dateslike :
date -d 'last-monday - 14 days' %Y%m%d from 20190315

date -d 'last-monday - 14 days' %Y%m%d from 20180217

date -d 'last-monday - 14 days' %Y%m%d from 201700914


and see the respective outputs.
by

1 Answer

Amit8z4mc
you should try this.
$ date
Wed Mar 20 15:02:23 MST 2021
$ date -d "last-monday"
Mon Mar 18 00:00:00 MST 2021
$ date -d "last-monday - 1 week"
Mon Mar 11 00:00:00 MST 2021

Login / Signup to Answer the Question.