How to get the week number in linux using gawk with different first day of the week? the date command can give me the week number with +%V but it is based on Monday (1-53) or +%U (based on Sunday, 0-53).

I tried to to do this: date -d "ddmmyy+2days" +%V, but the result is not correct. I want the first day of the week is based on Saturday.

Thanks

EDIT: add the criteria The first day of the week in my place is Saturday, and the first week is depend on the number of the day to the nearest Saturday. If the current week have less than 4 days before the nearest Saturday, then it will be counted to the last year week (52/53). It is the same with the week in the end of the year.

link|improve this question
be careful: the definiion of week-number (at least in business) might be tricky; for example, in many countries, week1 is defined as "the first week which has a thursday in it". Thus, week1 might end up being in the last year!. – blabla999 Jun 24 '11 at 8:15
yes, the first day of the week in my place is Saturday, and the first week is depend on the number of the day to the nearest Saturday. If the current week have less than 4 days before the nearest Saturday, then it will be counted to the last year week (52/53). It is the same with the week in the end of the year... – nandaka Jun 30 '11 at 6:11
feedback

migrated from stackoverflow.com Jun 25 '11 at 5:38

This question came from our site for professional and enthusiast programmers.

1 Answer

strftime (at least in gawk) can do that. E.g.:

awk '{print strftime("%U",systime()) ; exit }'

See the official documentation here: http://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html

link|improve this answer
The problem is: I want to get the week number of the date but with different first day of the week (for example: Saturday). The first day of the week for %U is Sunday, and %V is Monday. – nandaka Jun 30 '11 at 6:08
Then it's and added if statement, e.g. if ( strftime("%A",systime()) == "Saturday" ) { print strftime("%U",systime())+1 } else { strftime("%U",systime()) } – Zsolt Botykai Jun 30 '11 at 7:29
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.