Page 1 of 1
Get previous year from the string
Posted: Thu Oct 23, 2008 9:03 am
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
Posted: Thu Oct 23, 2008 10:21 am
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)?
Posted: Thu Oct 23, 2008 10:30 am
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
Posted: Thu Oct 23, 2008 9:17 pm
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
Posted: Thu Oct 23, 2008 9:20 pm
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
Posted: Thu Oct 23, 2008 9:46 pm
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.
Posted: Thu Oct 23, 2008 10:12 pm
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.