Home > database >  How do I get next week number in Bash?
How do I get next week number in Bash?

Time:12-05

I simply like to get the next week number of the year using Bash. I have a working script as follows but I am not pretty sure if it is the right way to do so. I have a concern specially around what it produces if the week is 52? Would output be 53 or 1?

echo $(($(date  %-V) 1))

CodePudding user response:

To get the next week number use:

nweek=$(date -d ' 1 week' ' %-V')
echo $nweek

49

Adding 1 to current week number will give wrong result of 53 for the last week of the year.

On the other hand, above command will give 1 for the same case because we are adding 1 week in the current date and then getting week number.

  • Related