Modify date that in string format to date format

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
happyds
Participant
Posts: 4
Joined: Fri Apr 20, 2007 9:46 am

Modify date that in string format to date format

Post by happyds »

Hello DS Experts! I'm trying to convert a date that is in a string datatype to a date datatype in a Modify stage, but am running into problems. The format of the string date value is different from the default format of "%yyyy-%mm-%dd", so I can't just use the "date_from_string(field_name)" specification.

Input string date value: 04/20/2007
Expected output value in date datatype: 04-20-2007

I tried using the following specification as specified in the Parallel Job Developer's Guide, but I keep receiving errors:
initial_date = date_from_string(initial_date) ["%mm-%dd-%yyyy"]

Please help me. Thank you.

Jessica
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You date is in the format mm/dd/yyyy and hence you need to give that format to the date_from_string() function. Then while loading it to a file you can specify change the default date format to mm-dd-yyyy.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
happyds
Participant
Posts: 4
Joined: Fri Apr 20, 2007 9:46 am

Post by happyds »

Thanks for responding! One of the problems I am having is knowing how to correctly specify the date format within the function. I have tried all variations, but each time DS throws a parsing error. Here is an example of one my specifications.

The specification is what I have entered in the Modify stage: Initial_Date=date_from_string (Initial_Date) [%mm/%dd/%yyyy]

The error I receive is the following:
main_program: Error parsing modify adapter: Expected ';' or end, got: "["; input:
Initial_Date=date_from_string (Initial_Date) [%mm/%dd/%yyyy];

Any ideas on what is the correct format to specify for the date format?

Thanks again,
Jessica
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Your specification is wrong. Provide the following

Code: Select all

initial_date:date = date_from_string [%mm/%dd/%yyyy]  (initial_date) 

And if your loading to a flat file, in the sequential file stage, go to "Format" tab, under "Type Defaults", go to the "Date" folder and enter %mm-%dd-%yyyy for "Format String"
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

In case you missed it, the part in square brackets goes ahead of the part in parentheses. The part in square brackets is the format string, the part in parentheses is the input column name.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
happyds
Participant
Posts: 4
Joined: Fri Apr 20, 2007 9:46 am

Post by happyds »

That worked! Thank you so much for your help!

Jessica
Post Reply