how to get end date of the month

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
RAJEEV KATTA
Participant
Posts: 103
Joined: Wed Jul 06, 2005 12:29 am

how to get end date of the month

Post by RAJEEV KATTA »

I have a scenario where in I need to take DSJobStartDate and find the end date of the previous month.I know how to get the end of the month but how do I go back to the previous month from DSJobStartDate.
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Hi

Post by neena »

Try this i got the logic from another post and modified the stage variables logic, but i am not sure.

Declare 3 stage variables like below.

SvRUN_DT = DSJobStartDate

svYear= YearFromDate(SvRUN_DT)

svMonth= MonthFromDate(SvRUN_DT)

Then in the output derivation for RUN_DT, put:

If MonthFromDate(RUN_DT) = 10 or MonthFromDate(RUN_DT) = 11 or MonthFromDate(RUN_DT) = 12 then
DateFromDaysSince(-1, StringToDate(svYear : "-" : svMonth : "-01") ) else DateFromDaysSince(-1, StringToDate(svYear : "-" : "0" : svMonth : "-01") )
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I would use the following logic:

1. Convert the DSJobStartDate to a string in the format YYYY-MM-DD
2. Replace the last two characters in the string with 01
3. Convert the String back to a Date
4. Subtract 1 day from the Date
neena
Participant
Posts: 90
Joined: Mon Mar 31, 2003 4:32 pm

Post by neena »

Try this logic, its somewhat similar to Arndw i guess.

Create one stage variable.

SvRUN_DT(Varchar) = DSJobStartDate[1,8]:01

Then in the output derivation for RUN_DT, put:

DateFromDaysSince(-1, StringToDate(SvRUN_DT) )
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

If DSJobStartDate = 2008-10-15, then subtract the number days. In this case, 15.

In DB2 SQL, this would be as follows:

Code: Select all

select current date - day(current date) days .....
or

Code: Select all

2008-10-15 - 15 days = 2008-09-30
Seems like this should always give you the last day of the prior month, shouldn't it? I haven't done much date arithmetic in DS, we typically are pulling from a database and do it in SQL. Does DS have an easy way to subtract N number of days from a date and have a valid date?

Brad
It is not that I am addicted to coffee, it's just that I need it to survive.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could use DayFromDate() to get the day number and DateFromDaysSince() to get the new date.
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