Previous Month Last 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
Ashish
Participant
Posts: 57
Joined: Tue Jan 31, 2006 1:16 am

Previous Month Last Date

Post by Ashish »

Hi,

How to get the last date of the previous month.?

Thanks
Ashish
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

DateFromDaysSince(-1, stringtodate(right(0:MonthFromDate(CurrentDate()),2):'-':'01':'-': YearFromDate(CurrentDate()),"%mm-%dd-%yyyy"))
Shantanu Choudhary
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Does this give the date of last day or the 1st day of previous month? When I manipulate it, I get the 1st day of previous month. If its last day, can you explain me the logic?

Regards,
Divya
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

SELECT TRUNC(SYSDATE)-1 AS LAST_MONTH_END_DATE FROM DUAL in oracle
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Laknar,
Your query give yesterday's date only. Moreover I think the requirement is in datastage and not oracle.

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

Post by Sainath.Srinivasan »

Make it

Code: Select all

trunc(sysdate, 'mm') - 1
then.
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

In oracle, that query is fine. But I think Ashish requires in datastage. Correct me if I am wrong.

Regards,
divya
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

talk2shaanc wrote:DateFromDaysSince(-1, stringtodate(right(0:MonthFromDate(CurrentDate()),2):'-':'01':'-': YearFromDate(CurrentDate()),"%mm-%dd-%yyyy"))
in datastage this should work fine.

this first derives the 1st day of current month and then subtracts 1 day from that.

in oracle sainaths code works fine.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Thanks for the explanation priyadarshikunal.

Regards,
Divya
Ashish
Participant
Posts: 57
Joined: Tue Jan 31, 2006 1:16 am

Post by Ashish »

priyadarshikunal wrote:
talk2shaanc wrote:DateFromDaysSince(-1, stringtodate(right(0:MonthFromDate(CurrentDate()),2):'-':'01':'-': YearFromDate(CurrentDate()),"%mm-%dd-%yyyy"))
in datastage this should work fine.

this first derives the 1st day of current month and then subtracts 1 day from that.

in oracle sainaths code works fine.

Hi guys,

Thanks for the information

Thanks Ashish
Post Reply