Blame

31b3db David Marsh 2026-04-23 05:19:29
1
# Date
2
252423 David Marsh 2026-04-23 05:27:14
3
*doing fun stuff with the linux date command*
4
31b3db David Marsh 2026-04-23 05:19:29
5
## Show the week number
6
f6b29c David Marsh 2026-04-23 05:27:31
7
```bash
8
date +%U
9
```
252423 David Marsh 2026-04-23 05:27:14
10
11
## ISO8601 format
12
13
```bash
66386f David Marsh 2026-04-23 05:28:37
14
date --iso
252423 David Marsh 2026-04-23 05:27:14
15
```
16
346395 David Marsh 2026-04-23 05:44:43
17
or using [homebrew](https://brew.sh):
18
19
```bash
20
gdate --iso
21
```
22
252423 David Marsh 2026-04-23 05:27:14
23
MacOS date command doesn't support `iso`, here are some useful variations:
24
25
```bash
66386f David Marsh 2026-04-23 05:28:37
26
date "+%Y-%m-%d"
27
```
28
```bash
fe50a0 David Marsh 2026-04-23 05:28:59
29
date "+%Y%m%dT%H%M%S"
252423 David Marsh 2026-04-23 05:27:14
30
```
31
32
## Yesterday and Tomorrow
33
34
```bash
35
$ date +%A --date today-1days
36
Wednesday
37
38
$ date +%A --date today+1days
39
Friday
40
41
$ date +%A --date yesterday
42
Wednesday
43
44
$ date +%A --date "2 days ago"
45
Tuesday
46
```
47
48
This also works as expected for other variables:
49
50
```bash
51
$ date +%Y --date "last year"
52
2011
53
54
$ date --date "next monday"
55
Mon Mar 19 00:00:00 EST 2012
56
```
57
58
Here's the entry from the `man` page:
59
60
```
61
DATE STRING
62
63
The --date=STRING is a mostly free format human readable date string
64
such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42"
65
or even "next Thursday". A date string may contain items indicating
66
calendar date, time of day, time zone, day of week, relative time,
67
relative date, and numbers. An empty string indicates the beginning
68
of the day. The date string format is more complex than is easily
69
documented here but is fully described in the info documentation.
70
```
71
72
*damn* you info docs!