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 advance.
Quote:
# !/bin/ksh
calcweek() {
if [ $LEAP -eq 0 ] ; then
set -A DIM 0 0 31 59 90 120 151 181 212 243 273 304 334
else
set -A DIM 0 0 31 60 91 121 152 182 213 244 274 305 335
fi
((JDAY=DIM[$MM]+DD))
((WEEK=(JDAY+$1)/7))
echo $YEAR-$WEEK
}
if [ $MMDD -le $JCUT ] ; then
if [ $PWK = 'XX' ] ; then
((PYEAR=YEAR-1))
((PYEAR%100)) && ((PLEAP=!(PYEAR%4))) || ((PLEAP=!
(PYEAR%400)))
((PWK=52+PLEAP))
fi
echo $((YEAR=YEAR-1))-$PWK
else
if [ $MMDD -ge $DCUT ] ; then
echo $((YEAR=YEAR+1))-01
else
calcweek $ADJ
fi
fi
Posix, in their wisdom, decided that a leading zero indicates an octal constant so 08 and 09 are illegal octal constants. This change broke a lot of code. Did you test for month=8 or 9? Also week number = 8 or 9?
Define precisely what you mean by week number. Are the first 7 days of the year always week 1?
Perderabo - I have checked for the month 08 and 09 it is working perfectly fo r other dates. it also works for the week 09 and 08 but the issue is only with the day being 09 or 08 any suggestions would be of great help. I have seen your code of sword fish(Gosh) thats a wonderful peice of work. I hope you have a solution for this as well. it is calculated with the ISO way like the first week could start as soon as 28th of dec or as late as 3rd of jan.
Oops!!!! and for perl -i dont have perl
Last edited by ahmedwaseem2000; 09-09-2005 at 07:11 AM..
Thanks for posting your final solution. I don't recall ever hearing of ISO week numbers before. So I will add this thread to our date arithmetic FAQ article. I found this page which has an on-line calculator for ISO week numbers.
For the record, here is a datecalc based solution. It emulates the behavior of the on-line calculator in that it outputs a year, a week number, and a day of week number...
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)
Hi anyone can help?
How to calculate total number of weeks from a specify date, for example, 01 Jan 2012.
Thx!
https://www.unix.com/images/misc/progress.gif (1 Reply)
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)
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)
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)
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)