Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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