Search code examples
bashsolarisdate

get week of year from day of year


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


Solution

  • 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