Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"This Friday" in bash script

Tags:

date

bash

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

like image 549
Ben Avatar asked May 19 '10 03:05

Ben


People also ask

How do I get tomorrow date in bash?

If you don't have GNU date, you can use the built-in date command with the -v option. returns tomorrow's date. returns tomorrow's date in the format YYYY-MM-DD.

How can I get yesterday's date in bash?

To get yesterday's date in bash shell you can use the Linux GNU date version with date -d yesterday or the Unix/macOS date version using date -j -v -1d .


1 Answers

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.

like image 81
Matthew Flaschen Avatar answered Sep 19 '22 08:09

Matthew Flaschen