Date calculation

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
mydsworld
Participant
Posts: 321
Joined: Thu Sep 07, 2006 3:55 am

Date calculation

Post by mydsworld »

How do we find the start & end date of next month or previous month.Is there any function to do that.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

There is, but you should have done a search before that.
Last date of the previous month -

Code: Select all

DateFromDaysSince(-1, StringToDate(RUN_DT, "%yyyy%mm") : "%yyyy-%mm-%dd") 
And First day of the previous month -

Code: Select all

StringToDate('01':MonthFromDate(RUN_DT,"yyyy%mm%dd")-1,YearFromDate(RUN_DT,"yyyy%mm%dd"))
Here RUN_DT is in yyyy%mm%dd.

And its better to use a stage variable for Month and Year, so the calculatin for December and January can be taken care with If - Then - Else.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
venkycool
Participant
Posts: 59
Joined: Fri Feb 16, 2007 12:24 am
Location: USA

Re: Date calculation

Post by venkycool »

Yeah Kumar is right and the code is also correct. create a stage variable for date and then give the derivations.
Suriv
No one is perfect... that's why pencils have erasers
Post Reply