get week of year from day of year

conandor picture conandor · Jul 12, 2010 · Viewed 26.6k times · Source

Given day of year, how can I get the week of year by using Bash?

Answer

Massimo picture Massimo · Jul 12, 2010

Using the date command, you can show the week of year using the "%V" format parameter:

/bin/date +%V

You can tell date to parse and format a custom date instead of the current one using the "-d" parameter:

/bin/date -d "20100215"

Then, mixing the two options, you can apply a custom format to a custom date:

/bin/date -d "20100215" +%V