date

doing fun stuff with the linux date command

2021-09-27

$ date --iso
2021-09-27

MacOS date command doesn’t support iso, here are some useful variations:

`` bash $ date “+%Y-%m-%d” 2021-09-27

$ date “+%Y%m%dT%H%M%S” 20210927T093333


Other tricks
------------

``` bash
$ date +%A --date today-1days
Wednesday

$ date +%A --date today+1days
Friday

$ date +%A --date yesterday
Wednesday

$ date +%A --date "2 days ago"
Tuesday

This also works as expected for other variables:

$ date +%Y --date "last year"
2011

$ date --date "next monday"
Mon Mar 19 00:00:00 EST 2012

Here’s the entry from the man page:

DATE STRING

The --date=STRING is a mostly free format human readable date string
such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42"
or even "next Thursday". A date string may contain items indicating
calendar date, time of day, time zone, day of week, relative time,
relative date, and numbers. An empty string indicates the beginning
of the day. The date string format is more complex than is easily
documented here but is fully described in the info documentation.

damn you info docs!