Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - date: difference between %V and %W

I want to get the week number using bash.

The man entry for date shows the following:

%V     ISO week number, with Monday as first day of week (01..53)
%W     week number of year, with Monday as first day of week (00..53)

Which is the difference?

This is the output I get:

$ date "+%W"
48
$ date "+%V"
48
like image 810
Manolo Avatar asked Jun 30 '26 02:06

Manolo


1 Answers

It's a bit more clear in the GNU docs (referenced in the man page):

https://www.gnu.org/software/coreutils/manual/html_node/Date-conversion-specifiers.html#Date-conversion-specifiers

‘%W’ week number of year, with Monday as first day of week (‘00’…‘53’). Days in a new year preceding the first Monday are in week zero.

‘%V’ ISO week number, that is, the week number of year, with Monday as the first day of the week (‘01’…‘53’). If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. (See the ISO 8601 standard.)

like image 114
JoseKilo Avatar answered Jul 03 '26 21:07

JoseKilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!