date command differs vastly between Linux & BSD systems. Mac, being based on BSD, inherits the BSD version of that
It took me longer to admit to figure out how to set a date in the future using the
date command on a Mac. It requires this arcane syntax.
EXPIRATIONDATE=$(date -j -f "%a %b %d %T %Z %Y" "`date -v+12H`" "+%Y-%m-%dT%H:%M:00")
The above takes “now + 12 hours” as the new date, and formats it as
"+%Y-%m-%dT%H:%M:00" - the last parameter.
-f flag indicates how to parse the date format supplied by the middle parameter.
To get a date in the future, you use the
-v command and supply the desired date shift:
This generates a new date 12 hours into the future. To supply multiple shifts, repeat the
date -v+12H -v-1d -v+10M
Which does: + 12 hours, -1 day, + 10 minutes.
The long command at the top outputs this:
I hope I won’t have to Google this again!