Converting string to date in modify stage

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
shukla_krishna
Premium Member
Premium Member
Posts: 28
Joined: Mon Apr 20, 2009 11:27 pm
Location: san antonio

Converting string to date in modify stage

Post by shukla_krishna »

Hi,

I wanted to convert one varchar field into date field using the modify stage. My input field is in the dd-mm-yyyy format and I used the below specification in the modify stage.

in_col:date = date_from_string "%dd-%mm-%yyyy"(in_col)

But I am getting the below error while running the job.

main_program: Error parsing modify adapter: Expected ';' or end, got: "%dd-%mm-%yyyy""
Expected destination field selector, got: ")"; input:
Dt_of_extrcn:date = date_from_string "%dd-%mm-%yyyy"(Dt_of_extrcn)
;


Please help me to resolve this issue.

Thanks
Last edited by shukla_krishna on Mon Jun 15, 2009 6:34 am, edited 1 time in total.
Krishna Shukla
sambarand
Premium Member
Premium Member
Posts: 22
Joined: Mon Apr 10, 2006 11:03 am

Post by sambarand »

Try using this :

Dt_of_extrcn:date = date_from_string(Dt_of_extrcn)

Make sure the input data type is of Varchar and output data type is Date for this column .
Sam
IBM Global Services
shukla_krishna
Premium Member
Premium Member
Posts: 28
Joined: Mon Apr 20, 2009 11:27 pm
Location: san antonio

Re: Converting string to date in modify stage

Post by shukla_krishna »

Thanks Sam. It works.

But my input data is in the format dd-mm-yyyy. Can I convert a string in the format dd-mm-yyyy to date field.
Krishna Shukla
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What is your default date format string? It is is not "%dd-%mm-%yyyy" then you need to specify the date format string - inside square brackets - in the Specification in the Modify stage.

Code: Select all

date_from_string[%dd-%mm-%yyyy](inputcolumn)
Note also that this will not work if your date is not precisely this format, for example 16/6/2009 or 16-6-2009 or 16/06/2009 will not work, but 16-06-2009 will.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply