Date conversion

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
balu124
Participant
Posts: 49
Joined: Wed Jul 25, 2007 9:53 pm

Date conversion

Post by balu124 »

Hi,
In the source the format of date field is dd-mon-yy(ex : 29-apr-05).
I need to extract the month number from it .and apply some more functions on this field .(probably date functions) ,to apply date functions the format of the date must be dd-mm-yyyy. how to solve this.
gbusson
Participant
Posts: 98
Joined: Fri Oct 07, 2005 2:50 am
Location: France
Contact:

Post by gbusson »

hi,

some date functions exist in the transformer or the modify.

Read the manual.

I'd like to add that date functions are not very powerful in Datastage. Try to use the database instead.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What IS "the source"? What data type is your date column? The answers to those questions will help a more targeted response to your questions.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
balu124
Participant
Posts: 49
Joined: Wed Jul 25, 2007 9:53 pm

Post by balu124 »

ray.wurlod wrote:What IS "the source"? What data type is your date column? The answers to those questions will help a more targeted response to your questions. ...
hi ray,
The source is sequential file .data type of that column is varchar.
gbusson
Participant
Posts: 98
Joined: Fri Oct 07, 2005 2:50 am
Location: France
Contact:

Post by gbusson »

no way to set the data type of your colmumn into "date"?

it will be easier!
balu124
Participant
Posts: 49
Joined: Wed Jul 25, 2007 9:53 pm

Post by balu124 »

gbusson wrote:no way to set the data type of your colmumn into "date"?

it will be easier!
hi gbusson,
how can I change the data type of a column when the data is present in the file ?

When I change the data type of date column in the column tab of sequential file stage, I am unable to view the data in the source file.
rsomiset
Premium Member
Premium Member
Posts: 46
Joined: Fri Sep 21, 2007 7:16 pm

Re: Date conversion

Post by rsomiset »

balu124 wrote:Hi,
In the source the format of date field is dd-mon-yy(ex : 29-apr-05).
I need to extract the month number from it .and apply some more functions on this field .(probably date functions) ,to apply date functions the format of the date must be dd-mm-yyyy. how to solve this.
Hi,
Use the ICONV and OCONV functions to get the date to your desired format and then apply the date functions what ever you want.
------
Rajesh
gbusson
Participant
Posts: 98
Joined: Fri Oct 07, 2005 2:50 am
Location: France
Contact:

Post by gbusson »

the problem is that Mon is not a valid format for PX.

ICONV and OCONV cannot be used in PX (unless using the basic tranformer or a server shared contanier) , since it is BASIC.

why don't you create a PX routine like this :

switch month :

case jan => 01
case feb =>02

Then you have the good format, you can transform into date.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I doubt a routine is necessary. Try the following in the transformer stage.

Code: Select all

StringToDate(in.col, "%dd-%mmm-%yy)
or its twin equivalent in modify stage.
Your output column should be defined as date.
Last edited by DSguru2B on Tue Nov 13, 2007 9:40 am, edited 1 time in total.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Date conversion

Post by gateleys »

rsomiset wrote:Hi,
Use the ICONV and OCONV functions to get the date to your desired format and then apply the date functions what ever you want.
------
Rajesh
Not in a PX job.

You may want to look at PX functions, probably date_from_string() or StringToDate().
Last edited by gateleys on Tue Nov 13, 2007 9:43 am, edited 1 time in total.
gateleys
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Date conversion

Post by gateleys »

Go with DSGuru's solution.
gateleys
Post Reply