Week number from a date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Week number from a date.
# 8  
Old 04-16-2012
before asking the command, you need to give your OS details.

Did you try my solution ?
# 9  
Old 04-17-2012
Itkamaraj > Your solution is not giving the week code of a year. Week code of a year varies from 1 to 52. Hope you understand the requirement.

OS & platform:SunOS-sparc
OS version : 5.10
# 10  
Old 04-17-2012
Please check your copy of man date. Your definition is more like date +%V which has range 01-53. Please do describe the rules for week number one.
e.g. According to ISO conventions 01/01/2012 this year is in week 52 of 2011. In date +%W it would be in week 00 of 2012.

Other posters have assumed that you have the GNU version of the date command which can do some date conversion. Without this program it is virtually impossible to achieve the desired result easily.

The Perl programmers may have a way. Similarly I've seen some pretty clever processing of the output of the cal command on this board.
# 11  
Old 04-18-2012
Also (a db connection might be expensive or you may not have mysql on your system), another possibility is:
Code:
mysql -u <username> -p<password> -e "SELECT WEEK('2012-04-04');"

# 12  
Old 04-18-2012
I refer you to the ISO definition of a week.
ISO week date - Wikipedia, the free encyclopedia

OK.
# 13  
Old 04-18-2012
# 14  
Old 04-19-2012
See
date(1): print/set system date/time - Linux man page

%G%V will give the year and week number

OK
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