I'm aware of date +%u
to get the day of the week for today.
I'd like to get that integer for any arbitrary date i input - if possible in the format I choose (eg %YYmmdd)
ok, found it finally:
date -j -f %Y%m%d +%u 20200910
this is, because date on macOS doesn't take a switch for putting in custom date (fyi for those folks, how try to make -v
work, like me^^)
in addition, -f affects only input format (it's literally the second word in the man page, but I managed to overlook more than once)
-j
is needed to use -f
without setting the date.
hope this will spare someone time in the future ;)
edit: it seems to be important, to specify input format before output format (see comment from @chepner below)
(also be careful with quotes)
$ date +%u -d "2020-09-10"
4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.