Week number from a date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Week number from a date.
# 1  
Old 04-16-2012
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.
# 2  
Old 04-16-2012
what is mean by week number ?

do you want to extract the date from the YYYYMMDD ?
# 3  
Old 04-16-2012
Week number means the week code...
for today the week code is 16 from the below command.
Code:
spdwa526:/axphome/rmund1(133)$date +%W
16

Similarly for any given date how can I know the week code?

Last edited by Franklin52; 04-17-2012 at 03:25 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 04-16-2012
Code:
 
$ echo "20120404" | awk '{print substr($0,5,2)}'
04

# 5  
Old 04-16-2012
Code:
date -d '20120404' +%W

# 6  
Old 04-16-2012
Code:
date --date=20120404 +%W

# 7  
Old 04-16-2012
Both of the above solutions are not working.
Code:
date -d '20120404' +%W
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

Can you please check & let me know exact command.

Last edited by Franklin52; 04-17-2012 at 03:24 AM.. Reason: Please use code tags for code and data samples, thank you
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

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

3. Shell Programming and Scripting

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: 2011 08 27 => 39 Thinks a lot (8 Replies)
Discussion started by: Castelior
8 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