Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

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

    
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

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

share|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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .