Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to use the 'date' command to display week number of the year?

I want the UNIX date to output:

So this is week 35 of 2021.

Here, of course, 35 and 2016 are outputs of the date command. I have tried the following
date +%U

This printed out the current week number. But I have to wrap it inside the specific text I want to display. I tried:

date "So this is week: %U"
date "It is currently: "+ "%U"


Both gave me an error. How can I make the date command display the week number to me in the specific format that I desire?
by

1 Answer

Kajalsi45d
The entire format string is to be preceded by the +:
$ date +"So this is week: %U"
So this is week: 19
$ date +"So this is week: %U of %Y"
So this is week: 19 of 2016

Login / Signup to Answer the Question.