Know the number of the week for a date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Know the number of the week for a date
# 1  
Old 11-29-2011
Know the number of the week for a date

Hi,

I tried to find the solution on the forum without success.
datecalc from Perderabo doesn't solve my problem.

I would like to know how to do the same thing that date +%U but for a specific date.

For example:
Code:
2011 08 27
=> 39

Thinks a lot

Last edited by Castelior; 11-30-2011 at 05:22 AM..
# 2  
Old 11-29-2011
Do you have GNU date?
Code:
# date -d"01 Aug 2011" +%U
31

# 3  
Old 11-29-2011
Quote:
Originally Posted by CarloM
Do you have GNU date?
Code:
# date -d"01 Aug 2011" +%U
31

No I don't... Can I install it? and how? I'm on AIX.

Thanks
# 4  
Old 11-29-2011
It's part of coreutils.

iirc, IBM offer a coreutils RPM for AIX.
# 5  
Old 11-29-2011
# 6  
Old 11-29-2011
Do you have Perl installed? Try this:
Code:
perl -e '@x=localtime; print int $x[7]/7 + 1'

But this will give you the week number for current time. Similar to "date +%U".
# 7  
Old 11-29-2011
Another one... Check if you have ncal...
Code:
ncal -w 8 2011 | awk '{for(i=2;i<=NF;i++){if($i==27){col=i;next}}}END{print $(col-1)}'

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

2. Shell Programming and Scripting

Week number from a date.

Hi, How can we get the week number from any paricular date. lets say date is 20120404 (YYYYMMDD) then how to get the week number? date +%W --- Thic command gives the week number for current date only. Thanks. (13 Replies)
Discussion started by: 46019
13 Replies

3. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

4. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

5. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

6. UNIX for Dummies Questions & Answers

week number

how can I display week number using 'date' command. ?? in the manual it says " %w day of week (0..6); 0 is Sunday" I did not get it? help please. Alice (2 Replies)
Discussion started by: alisevA3
2 Replies

7. Shell Programming and Scripting

calcuate the week number of a given date

Hi All, can any one help me fix the error in this - i am still a novice in shell programming. I got this code after some googling now the code works with all the dates( as much as i know) except for 08 th and 09th of every month. can any one of you please help me fix this issue? Thanks in... (11 Replies)
Discussion started by: ahmedwaseem2000
11 Replies
Login or Register to Ask a Question