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
Written by Alexey Alekhin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Date
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#