I want to get a date-time string in the future, for example I always want to get the next time of 9:00 am.

I know the string formats like "tomorrow" or "next day" to get a certain date-time string. But if I call $(date -d 'tomorrow 09:00') early in the morning of the Nov. 26 2015, I get Nov 27 09:00:00 2015. But I would expect to get Nov 26 09:00:00 2015, because it is the next 9th hour.

How do I get the next occurrence of the 9th hour of a day instead? Are there other key-words like "next occurence of 09:00"?

  • No, isn't: If date is called before 09:00 it should get 09:00 of the current date. If it is called after 09:00 it should get 09:00 of the next day.
    – shylynx
    Nov 26, 2015 at 21:29

1 Answer 1

next0900=$([ $(date +%H) -lt 9 ] && date -d "09:00" || date -d "tomorrow 09:00")

If the current hour is less than 9, then give me "9:00" otherwise give me "tomorrow 9:00"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .