last day of the month of a given date

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Swaruparani
Participant
Posts: 5
Joined: Wed Sep 12, 2007 1:54 am
Location: Bangalore

last day of the month of a given date

Post by Swaruparani »

i will pass a date an input ,i need to get the last day of that month.

EX:if i will pass 2009-02-16 as input then my expected output should be 28(last day of FEB)

Thanks in advance.
Swarupa
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard.

This is a perfect example of something most easily resolved using a time "dimension" (lookup) table at day granularity.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

ray.wurlod wrote:This is a perfect example of something most easily resolved using a time "dimension" (lookup) table at day granularity.
Yes, It is. But if its a straight forward requirement then transforming it to 1st of next month -1 day is not a bad idea.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

Search is your friend :)

you can do it via oracle procedure too

CREATE FUNCTION dbo.LastMonthDay
( @Date datetime )
RETURNS datetime
AS
BEGIN
RETURN (CASE WHEN MONTH(@Date)= 12
THEN DATEADD(day, -1, CAST('01/01/' + STR(YEAR(@Date)+1) AS DateTime))
ELSE DATEADD(day, -1, CAST(STR(MONTH(@Date)+1) + '/01/' + STR(YEAR(@Date)) AS DateTime))
END)
END
GO
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

If you can use oracle query then you don't need a procedure to do the same. there is a function called Last_day() in oracle which gives you last day of the month without any effort.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Where did the original question mention Oracle?
:roll:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Can do something like
endOfMonthDate = YYYY + INT(MM / 12) : MOD(MM, 12) + 1 : 01 - 1
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

ray.wurlod wrote:Where did the original question mention Oracle?
:roll:
I was just replying to the post above suggesting to use a oracle procedure.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What if they're a DB2 shop? You've been in Ireland too long!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

What if they're a DB2 shop?
Then they must have started searching for me. :wink:
You've been in Ireland too long!
Yes.
Something wrong with the language or nature of reply?
then I must start thinking on that.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

I just figured out your opinion about Ireland. :wink:
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is a very old joke, though many say it's true, that goes something like this. A visitor to Ireland asks directions to a particular attraction, and gets the reply "well, if I were going there, I wouldn't be starting from here".
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