'WEEK.TAG' with Sunday as start of week

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

'WEEK.TAG' with Sunday as start of week

Post by sohasaid »

Dears,

I was wondering about how to customize the 'WEEK.TAG' and 'ConvertWeek' function to retrieve a week which starts with Sunday instead of Monday.

Regards.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

WeekdayFromDate() allows you to specify the origin day as an optional parameter.
Returns the day number of
the week from the given
date. Origin day optionally
specifies the day regarded
as the first in the week and
is Sunday by default
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

ArndW, I tried to use WeekdayFromDate() in a transformer but derivation is getting red.
What's I'm trying to do is getting the week of year by using WEEK.TAG but with week starts at Sunday.

I don't know how to use WeekdayFromDate() in the previous context.

Thanks for your reply.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sorry, that was my mistake - I was thinking of Parallel functions and just now realized that you meant a server job. I'm sorry about that.

I would write my own routine and use 3 ICONV/OCONV calls:

Code: Select all

InternalDate = ICONV(InputDate,"D4/YMD[2,2,2]") ;** assuming that is your date string format
JulianDate = OCONV(InternalDate,"DJ")
FirstDayOfYear = OCONV(InternalDate-JulianDate+1,"DW")
Knowing what day of week your first day of the year was, and what day of the year you want to compute a calendar week for, you can perform your own calendar week calculations.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The change to ConvertWeek function should be fairly easy. What have you attempted?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Pretty sure the change needed is documented, but have no ability to check any more. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

ArndW, I've tried tried your routine and it gives the following output:

InternalDate, JulianDate , FirstDayOfYear , DayName , Date
14637, 27 , 3 , Sunday , 2008-01-27
14647, 37 , 3 , Wednesday , 2008-02-06

I don't know why the 'FirstDayOfYear' is always '3' for these records?

Ray, I'm not pretty handy with Basic, but I've tried to reassign the DayOfWeek values in WEEK.TAG to start from 0 to 6 as 0 is Sunday and 6 is Saturday, but it didn't work and it gives the same result as before.

Craig, I didn't find it unfortunately in my search :(

Regards.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Not exactly sure what you are trying to achieve.

But wouldn't it be simple to pass "Date + 1" as input argument to get the correct week starting Sunday ?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I will have to see the code for WEEK.TAG, I can't remember it.

To the First day of the year - that is always the same day when in the same year, thus your value is identical.
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

Sainath, It's not working.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

sohasaid wrote:Sainath, It's not working.
What is that supposed to mean ? Can you please explain in detail than just "it's not working".

Do you get any error ? Is there any problem in the output ? What value did you pass ? What you expect vs what you get.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sainath, my motorcycle isn't working; can you help me too?
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

ArndW wrote:Sainath, my motorcycle isn't working; can you help me too?
Oh Yeah !! It has run out of petrol.

I get one nice summer day in London and people are ready to spoil it. :(

PS : Good one ArndW !! Btw, yours is a bicycle and not a motor cycle. :wink:
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

Sorry for not mentioning the details.

I tried to pass 'Date+1' as 'Sainath' suggested by doing this:

DateOne : OCONV(InternaltDate+1, 'D-YMD[4,2,2]') as stage variable
Calender Week : TAG.TO.WEEK(DateOne)

The problem always in the last week of year, which depends on the number of days at the lase week week in year. If number of days at last week < 4, it works fine. Otherwise, week number is even increased or decreased by one (i.e. week 53 instead of 52 or week 1 instead of 53,...)

PS : Nice one ArndW.

Regards & thanks for help.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All years have a 53rd week under the business rule that every week has exactly seven days. 365/7 = 52.14... and 366/7 = 52.28...

Maybe you need to specify your business rule more carefully.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply