GNU date
, with that non-standard -d
option, only supports a limited set of date-time formats documented at info date 'Date input formats'
(and online here).
For a date
implementation that supports more date formats including the one you're referring to, you can use the date
implementation from ast-open
(which can also take an input date with -d
like GNU date
).
That can also be the date
builtin of the ksh93 shell if built as part of ast-open
(rarely the case though), or instead of date
, you can use its printf
builtin (which is always included) and its %T
specifier (which bash
copied though without the time parsing part):
$ builtin date
$ date -d '2021-W50-3' +%F
2021-12-15
$ printf '%(%F)T\n' 2021-W50-3
2021-12-15
From the bash
shell (or any other shell), you can always do it as:
$ ksh93 -c '"${@:0}"' printf '%(%F)T\n' 2021-W50-3
2021-12-15
though note that depending on the system, ksh93 may be known as ksh
, ksh2020
(or even sh
like on Solaris 11+; though it's also known as ksh
there), or not at all, as ksh93, like bash or zsh is not installed by default on all systems.
Note that while standard strftime()
can produce dates in that standard format with the %G-%V-%u
specification, the corresponding standard function to parse timestamps (strptime()
) doesn't support %G
nor %V
(nor does standard UNIX getdate()
).
GNU strptime()
is currently documented to understand them (as an extension over the standard) but ignore them (see info libc strptime
). FreeBSD strptime()
is documented to support the same directives as strftime()
but in my test on FreeBSD 12.2 (using zsh
's strftime -r
builtin), it doesn't seem to work there.
POSIX, GNU and freebsd strptime()
do support %W
though.
%Y-%W
is not the same as %G-%V
though, it just happens to coincide in this case. %W
on the first of January is 00 unless that's a Monday in which case it's 01. Whilst %V
(the ISO week number) is either the first week of the year (01) or the last week of the previous year (52 or 53) depending on whether that week has more days in the previous or current year.
date
? Did you trydate -d '2021-01-01 +51 weeks'
?date
not understand the special format date string that I've invented?" or "how do I calculate the dates of a particular week?"date
. I'm using the built-indate
command in my distro (Fedora 33). I'm just curious as to whydate
doesn't support such standardized format.