Last Updated: February 25, 2016
·
512
· laughedelic

Week number to date

Here is a function, which takes number of week (and optionally year) and returns date of it's Monday:

function monday() {
    local week=$1
    local year=${2:-$(date +%Y)}
    local fst_week_day=$(date -d $year-01-01 +%u)

    date -d "$year-01-01 -$((fst_week_day - 1)) day +$(($week - 1)) week" +%F
}

To get other week days you can use date, for example for Sunday:

function sunday() {
    date -d "$(monday $*) +6 day" +%F
}

To change format, again use date:

> date -d "$(monday 13 2013)" +%d.%m.%Y
25.03.2013