Last Date of Previous 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
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Last Date of Previous Month

Post by Prashantoncyber »

Hi all,

We need to run a job once any time in a month.
Which can populate a column in the table/file with the last date of previous month.
Your help shall be appreciated.

Thanks
Prashant
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I am not at a PX computer or have access to the documentation, but the route I would take is:

Code: Select all

DateFromDaysSince(-1,StringToDate(DateToString(CurrentDate(),'%yyyy%mm%dd')[1,6]:'01'))
You might have to weed out the syntax errors and/or function names yourself, but the basic functionality is

a) take today's date as a string with the 'dd' part at the end
b) rebuild a date variable by replacing the 'dd' with the first day of the month
c) subtract one day from that date
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Post by Prashantoncyber »

Tried by but not fetching proper result.
Looks like need some other approach.

Thanks
Prashant
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

ArndW wrote: DateFromDaysSince(-1,StringToDate(DateToString(CurrentDate(),'%yyyy%mm%dd'& ...

I guess this will work if u give the first day of the month. -1 will probably give the previous date. try giving the day instead of one and see. i.e if the date is 21-11-2006. give the argument as -21 instead of -1. See if this works.
Ragunathan Gunasekaran
Participant
Posts: 247
Joined: Mon Jan 22, 2007 11:33 pm

Re: Last Date of Previous Month

Post by Ragunathan Gunasekaran »

Hi ,
Are you using oracle table as the target stage ?.....
If so you can edit the insert statement generated by datastage to the following
insert into table_name values (...,trunc(sysdate) -1)
i think this would solve the problem . But if the datastage server and the oracle server are not in the same machine this may not produce an expected date. . .

Just check this out . . . It may not be a solution within the datastage job design but from the database side
Regards
Ragu
JeroenDmt
Premium Member
Premium Member
Posts: 107
Joined: Wed Oct 26, 2005 7:36 am

Post by JeroenDmt »

Prashantoncyber wrote:Tried by but not fetching proper result.
Looks like need some other approach.

Thanks
Prashant
The approach is correct.
Try

Code: Select all

DateFromDaysSince(-1,StringToDate(DateToString(CurrentDate(),'%yyyy-%mm-%dd')[1,8]:'01'))
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Post by Prashantoncyber »

Tried by but not fetching proper result.
Looks like need some other approach.

Thanks
Prashant
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi Prashant,
What is the exact procedure that you tried and what is the result that you got which is not expected.
Have you made a search?
Have you tired

Code: Select all

DateFromDaysSince(-1, StringToDate(DateToString(CurrentDate(),"%yyyy%mm"), "%yyyy%mm") : "%yyyy-%mm-%dd") 
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Odd, this approach works for me. Please post what the incorrect result is.
Prashantoncyber
Participant
Posts: 108
Joined: Wed Jul 28, 2004 7:15 am

Post by Prashantoncyber »

After carefully checking, it worked properly.

Thanks guys for your help.

Time to mark this topic resolved.

Thanks
fareeda_b
Participant
Posts: 48
Joined: Sat Feb 23, 2008 4:25 pm

Post by fareeda_b »

Hi Prashanth ,
could you please explan me how this date issue got resolved ?

thanks
fareeda
Thanks
fareeda_b
Participant
Posts: 48
Joined: Sat Feb 23, 2008 4:25 pm

Post by fareeda_b »

Hi Prashanth ,
could you please explan me how this date issue got resolved ?

thanks
fareeda
Thanks
Post Reply