To find the total number of days

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

Post Reply
SHARAD123
Premium Member
Premium Member
Posts: 54
Joined: Wed Jan 09, 2008 12:05 am

To find the total number of days

Post by SHARAD123 »

Hi, Is there any way to find the total number of days in a month using the transformer stage?
222102
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure. How about subtracting the first day of the target date (internal format) from the first day of the next month, then subtract 1?
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Use a TIME dimension table and make one of its columns the number of days in the month of the date.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
SHARAD123
Premium Member
Premium Member
Posts: 54
Joined: Wed Jan 09, 2008 12:05 am

Thnk u guys

Post by SHARAD123 »

I used the last_day(field name) fn of oracle in the sql space n got the number of days..

I ll try out your ideas too..
thnx anyway..
222102
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Thnk u guys

Post by gateleys »

As Kenneth suggested, you could use the TIME dimension. Assuming that you are developing a data warehouse, the model will always contain a TIME dimension. Further, it is a common practice to include the number of days in the month as a column in that dimension.
gateleys
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yes, of course. I didn't pony that up (or the Oracle solution) as I thought the OP asked for a code solution 'using the transformer stage' and didn't mention the 'O' word.

Time to mark the thread as something - Resolved or Worked Around, regardless.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

In that case - except for when the Pope fiddled with the calendar - you could use a simple mapping from month number (and year number in the case of February) to number of days in the month.

Code: Select all

Iconv(TheDate, "DM")                        ----->  svMonth
Iconv(TheDate, "DY")                        ----->  svYear
"31;28;31;30;31;30;31;31;30;31;30;31"       ----->  svMonthDaysList
Mod(svYear,4) = 0 And Mod(svYear,400) <> 0  ----->  svIsLeapYear 

Field(svMonthDaysList, ";", svMonth, 1) + svIsLeapYear
You *could* do that all in one expression; I feel that stage variables make it neater, more efficient (only need to calculate Iconv() once each) and easier to maintain.
Last edited by ray.wurlod on Mon Jan 14, 2008 6:42 pm, edited 2 times in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Re: Thnk u guys

Post by kcbland »

gateleys wrote:As Kenneth suggested, you could use the TIME dimension. Assuming that you are developing a data warehouse, the model will always contain a TIME dimension. Further, it is a common practice to include the number of days in the month as a column in that dimension.
A Time "table" should exist in every single business IMO. We used to call them a "CALENDAR" table back in my early days. An algorithm is worthless when companies have different "open for business" rules. Some honor one holiday and not the other, etc. It was intolerable for IT (or DP as we used to be called) to have to always update programs/common libraries with the latest information as for which days were exceptions to the rules in order to get numbers to turn out right. A simple calendar table makes everything easier, but seems to be out-of-fashion these days. :cry:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Totally agree, Ken, it should. When I was warehousing we always had one and it came in quite handy for things like you mentioned - all things date were answered there. However, recent efforts I've witnessed seemed to not even consider it. Damn kids.

The OP only asked for the total number of days in any given month (something suited to an algorithm) not anything like 'business days' or my answer would have closely mirrored yours. :wink:

Now, the 'content store' that is my life's work at the moment has no such beastie in it and no need for one, it seems. For whatever that is worth.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply