0

Manual page for date(1) says:
%W week number of year, with Monday as first day of week (00..53)

I assumed there exists a week number 00, and I handle such week in my program, but once I decided to test it, execution of
'date -v -28w +%W' results in 01, and
'date -v -29w +%W' results in 52.

Is it possible for some year to get week 00, or what is happening here? Probably I'm missing something, thanks.

1 Answer 1

1

Any day of the year before the first Monday will be week 00. Take January 1 2020 for instance, which was a Wednesday (the first Monday of 2020 did not occur until January 6):

$ date -d "2020-01-01" +%W
00
$ date -d "2020-01-02" +%W
00
$ date -d "2020-01-03" +%W
00
$ date -d "2020-01-04" +%W
00
$ date -d "2020-01-05" +%W
00
$ date -d "2020-01-06" +%W
01

Likewise, for years that start on a Monday, there will be some days in December that fall into week 53. 2018 was such a year:

$ date -d "2018-12-31" +%W
53
1
  • Thanks! So it was a coincidence I ran it on Monday :) Commented Jul 20, 2020 at 16:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .