How to use the 'date' command to display week number of the year?
The entire format string is to be preceded by the +
:
$ date +"So this is week: %U"
So this is week: 19
$ date +"So this is week: %U of %Y"
So this is week: 19 of 2016
There are two kinds of week:
- Monday as first day
- Sunday as first day
So its not all the same when you are in different day of a week(CentOS7):
[[email protected]:~]# date
Mon Aug 26 18:02:47 CST 2019
[[email protected]:~]# date +%U
34
[[email protected]:~]# date +%V
35
date --help
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
There are actually 3 kind of week number in year for the date command :
- %U week number of year, with Sunday as first day of week (00..53)
- %W week number of year, with Monday as first day of week (00..53)
- %V ISO week number, with Monday as first day of week (01..53)