tags:

views:

68

answers:

1

Hi,

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?

Cheers Ben

EDIT: I'm on a mac

+5  A: 

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.

Matthew Flaschen
If that command is run on Sat/Sun, will it return this week date or next week date?
DJ
@DJ, I think it always returns today or a future day, within 7 days from the start of today. For me, it's currently Wed. the 19th, so 'this Tuesday' gives Tue. the 25th. An interesting point is that 'this Wednesday' gives the 19th, while 'next Wednesday' is the 26th.
Matthew Flaschen
Next week date. According to the `date` docs, "this" is equivalent to not specifying anything, so it looks for the next Friday which occurs.
Porges
Thanks for the tip. What's the equivalent of date -d on Mac ? (Sorry I should have mentioned that)
Ben
I've worked it out on the mac.. date -v+Friday or date -v+Friday "+%s" for the timestamp
Ben
Thanks for putting me in the right direction!
Ben
More relative dates: Today (Wednesday) using "Friday" and "next Friday" both give "May 21". You can do "Friday week" to get "May 28" or "Friday 2 weeks" to get "June 4".
Dennis Williamson