"This Friday" in bash script

bash, date

Solution

With GNU date:

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

See Relative items in date strings, part of the GNU date documentatoin. There are also examples.

Problem

Is there a way to calculate a time stamp for the next coming up of a week day? So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it. I know the date command can parse a given string date according to a format, but I can't figure out how to calculate "next friday from today" Any idea? EDIT: I'm on a mac

Original source