LAST DAY of The Month given YEAR and 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
kbsuryadev
Premium Member
Premium Member
Posts: 46
Joined: Wed Jun 06, 2007 10:32 am

LAST DAY of The Month given YEAR and MONTH

Post by kbsuryadev »

Just wanted to share a solution.


Input:

YEAR=2011 (YYYY)
MONTH=2/02 (M/MM)


Output: Date

2011-02-28


Code:
StgMonth
If MONTH EQ 12 Then StringToDate(YEAR+1: "-" :"01": "-" :"01","%yyyy-%mm-%dd") ELSE StringToDate(YEAR: "-" :Right('00': ( MONTH+1),2): "-" :"01","%yyyy-%mm-%dd")

StgJulianDate
JulianDayFromDate(StgMonth)

StgLasyDat
DateFromJulianDay(StgJulianDate-1)

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

Post by ray.wurlod »

So, in words, "the day before the first day of the next month".
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