"This friday" in a bash script

Is there a way to calculate the timestamp for the next next day of the week?

So, for example, from Monday, I would like to be able to run a code that calculates this from today on Wednesday 19/05/10, next Friday will be 21/05/10 and get a timestamp from it,

I know that the date command can parse a given string date according to the format, but I cannot figure out how to calculate "next Friday from today"

Any idea?

EDIT: i'm on mac

+6
date bash
source share
2 answers

With GNU date:

date -d 'this Friday' '+%d/%m/%y' 

See Relative elements in date strings , part of the GNU dateato date document. There are also examples .

+11
source share

Since the format is not specified, it is much simpler:

 date -d Fri 

'this' is considered a default, Friday can be shortened. Since this is just one word - or a significant part of it, (ask Th), it does not need quotes such as

  date -d "last Fri" 

will be.

+1
source share

All Articles