Link to home
Start Free TrialLog in
Avatar of mahjag
mahjag

asked on

unix k shell script on dates

I need a script in ksh that when I provide a month and year as input let us say JAN-2009 then it should split the dates into weeks and I need to store them as

WEEK1_START = '2009-01-01-00.00.00'
WEEK1_END = '2009-01-09-00.00.00'
WEEK2_START =  '2009-01-09-00.00.00'
WEEK2_END = '2009-01-16-00.00.00'
WEEK3_START ='2009-01-16-00.00.00'
WEEK3_END = '2009-01-23-00.00.00'
WEEK4_START = '2009-01-23-00.00.00'
WEEK4_END =  '2009-02-01-00.00.00'

Let me know how to get this.. I wanted weekly dates in this format since I wanted to use the above values in my db2 script which has datetime as datatype.. Thanks!!
Avatar of ozo
ozo
Flag of United States of America image

how do you decide when a week starts and ends?
it looks like your weeks are 8, 9, or 10 days long, and usually start and end on a Friday.
Can you explain the rules for how that works?
Avatar of mahjag
mahjag

ASKER

We got this from a customer response and would like to stick with the same dates for any month, let me know if that will be an issue..
So, always 1st to 9th, 9th to 16th, 16th to 23rd, and 23rd to 1st?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mahjag

ASKER

Hi Ozo

I just ran the script above and got error
./weekly_dates.ksh[14]: typeset: bad option(s)
do you know why?
Avatar of mahjag

ASKER

I looked at man typeset and did not see option for -n
I changed that value to -x and still got syntax errors. Hope I get a solution that is tested, here is the syntax error..
./weekly_dates.ksh[23]:   % 12 + 1 : syntax error - any clues?
Avatar of mahjag

ASKER

I know this question is closed - but would like to get some response here to complete the task.
what version of ksh are you running?