Get previous year from the string

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
harshada
Premium Member
Premium Member
Posts: 92
Joined: Tue May 29, 2007 8:40 am

Get previous year from the string

Post by harshada »

Hi,

I have a string for eg 08. I need to convert it into year and get the previous year.

I tried OUT=DateToString((StringToDate(PAR_ERT_YY,"%yy")-1)) and OUT column is a varchar (2).

I get an error while compiling...

Invalid conversion requested from a dfloat to a date.

Can anyone help me on this?

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

Post by ArndW »

You are looking to convert a string number into a VarChar(2) year value. I don't think you need to use any date functionality here. How long is the source? Can you do a right(trim(In.StringValue),2)?
chaks
Premium Member
Premium Member
Posts: 39
Joined: Wed Nov 22, 2006 9:21 pm
Location: MA

Post by chaks »

Hi Harshada,
Your approach is not appropriate, what if the year is 2100, I suggest you to take the year as %yyyy and then Minus 1 in a stage variable and then take Right(Col1,2) in the derivation

Regards
Shiva
harshada
Premium Member
Premium Member
Posts: 92
Joined: Tue May 29, 2007 8:40 am

Post by harshada »

Hi,

I took a stage variable SvDate as date and
SvDate=StringToDate(CurrentDate() [1,2] : PAR_ERT_YY,"%yyyy")-1

where PAR_ERT_YY will have value of year for eg 08.

Then in the OUT column i use SvDate.

But still I get the same error

Invalid conversion requested from a dfloat to a date.

Why is it saying dfloat when my input is a string and output is a date
harshada
Premium Member
Premium Member
Posts: 92
Joined: Tue May 29, 2007 8:40 am

Post by harshada »

Hi,

I took a stage variable SvDate as date and
SvDate=StringToDate(CurrentDate() [1,2] : PAR_ERT_YY,"%yyyy")-1

where PAR_ERT_YY will have value of year for eg 08.

Then in the OUT column i use SvDate.

But still I get the same error

Invalid conversion requested from a dfloat to a date.

Why is it saying dfloat when my input is a string and output is a date
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Because intermediate arithmetic results are dfloat. The result of StringToDate() has to be converted to a numeric data type (dfloat) before 1 can be subtracted from it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
harshada
Premium Member
Premium Member
Posts: 92
Joined: Tue May 29, 2007 8:40 am

Post by harshada »

Hi,

I got it, took the stage variable as varchar2 SvDate

SvDate= (CurrentDate() [1,2] : PAR_ERT_YY)-1

as simple as that..


Thanks anyways.
Post Reply