week-number.net
Week number in Linux/Unix Shell Script
In Linux/Unix Shell scripts you can use the date
command to format dates.
This works on all disributions like Ubuntu, Mint, Suse, Debian etc. and also on the MacOS X command line.
Example: Command line
Get the current week number and print it on the interactive shell.
$ date +%v
Output:
3
--
Example: In a script
Assign the current week number to a variable and print it.
weeknumber=`date +%V`
echo "Week number:$weeknumber"
Output:
Week number:3
--
Example: Week number of fixed date
To get the calendar week number for a specific date, use the following command:
date --date="1984-12-18" +"%V"
Output:
51
comments powered by Disqus