Getting the week number based on date with different first day of the week in gawk

0

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.

nandaka

Posted 2011-06-24T08:03:32.360

Reputation: 1

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!. – None – 2011-06-24T08:15:21.623

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 – 2011-06-30T06:11:01.780

Answers

0

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

Zsolt Botykai

Posted 2011-06-24T08:03:32.360

Reputation: 627

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 – 2011-06-30T06:08:11.000

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 – 2011-06-30T07:29:36.823