Conversion of date from (Mon dd yyyy hh:mmAM) to (dd-mon-yyy

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Conversion of date from (Mon dd yyyy hh:mmAM) to (dd-mon-yyy

Post by dprasanth »

Hi,
I am very much new to datastage. I am having a sequential file that I am using as an input stage. The file has the following record format

1|517032108|"NULL"|97|"Apr 12 1998 12:00AM"|""|"M"|"SYSTEM"|"09-06-2002"|"N"|"END^M"

I have to convert the date Apr 12 1998 12:00AM to 12-Apr-1998 12:00AM. Can you please let me know how this can be done.

Thanks in Advance
Dprasanth
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
Welcom Aboard :D
I havnt tried sever job codes yet, still this should work

Code: Select all

Oconv(Iconv("Date_Time.field","DMTH"),"D-DMYMTH")
regards
kumar
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You need to do this in 2 steps, first convert the date portion into internal format telling it what the formatting is, then convert it to an output format in the new format.

OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99]

This takes your text date and tells Datastage the the format is D4MDY, so Date format, 4 digits for the year, in the order month, day, year. DataStage is intelligent enough to understand that the separator is space and that the month is in text form. The output just shifts the ordering around.
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ArndW wrote:You need to do this in 2 steps, first convert the date portion into internal format telling it what the formatting is, then convert it to an output format in the new format.

OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99]

This takes your text date and tells Datastage the the format is D4MDY, so Date format, 4 digits for the year, in the order month, day, year. DataStage is intelligent enough to understand that the separator is space and that the month is in text form. The output just shifts the ordering around.
Anrdw.. I tried what you told me and still I am not able to find the date formated. The output file shows me the same result.
Kumar,
I tried your conversion also, but it doesn't work :(
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ArndW wrote:You need to do this in 2 steps, first convert the date portion into internal format telling it what the formatting is, then convert it to an output format in the new format.

OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99]

This takes your text date and tells Datastage the the format is D4MDY, so Date format, 4 digits for the year, in the order month, day, year. DataStage is intelligent enough to understand that the separator is space and that the month is in text form. The output just shifts the ordering around.
I have a small query, sorry if I sound silly, I don't understand why we have D4 OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99].Does that signify anything?
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

dprasanth wrote:
ArndW wrote:You need to do this in 2 steps, first convert the date portion into internal format telling it what the formatting is, then convert it to an output format in the new format.

OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99]

This takes your text date and tells Datastage the the format is D4MDY, so Date format, 4 digits for the year, in the order month, day, year. DataStage is intelligent enough to understand that the separator is space and that the month is in text form. The output just shifts the ordering around.
I have a small query, sorry if I sound silly, I don't understand why we have D4 OCONV(ICONV(In.DateColumn[1,11],'D4MDY'),'D4DMY'[2,3,4]):In.DateColumn[12,99].Does that signify anything?
Andw,
Sorry.. i think there is some problem with our input file. i will just reformat the input file and will try your conversion again
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

dprasanth,

yes, it does signify something, it is the output format. Please open up the BASIC programmer's guide on your PC and look up the chapter on conversion codes, specifically for the Date conversion. There are examples in there that should clear up some of your questions.
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ArndW wrote:dprasanth,

yes, it does signify something, it is the output format. Please open up the BASIC programmer's guide on your PC and look up the chapter on conversion codes, specifically for the Date conversion. There are examples in there that should clear up some of your questions.
Excellent.. thanks for your advice.
Thanks
Dprasanth
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There are also good examples in on-line help for Oconv.

This article is also informative.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ray.wurlod wrote:There are also good examples in on-line help for Oconv.

This article is also informative.
Thanks a lot to everyone who answered my query. I was able to get loads of information by going through the documents
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

I tried using the conversion Oconv(Iconv(DSLink17.AttendanceDate[1,11],"D MDY"),"D DMY[2,2,4]"):DSLink17.AttendanceDate[12,99] and I am able to convert teh date from the input format to the output format. But Oracle is complaining when I am inserting that to the database
This is the input record
3|DET|1|517032108|NULL|97|Apr 12 1998 12:00|E|M|SYSTEM||| and this is the output record

RNK_SEQOCI_V2..Transformer_29: The value of the row is: ATTENDANCE_ID = 1 CUSTOMER_ID = 517032108 HostMember_ID = 0 Club_ID = 97 Attendance_Date = 12 04 1998 12:00
Oracle gives me this error
RNK_SEQOCI_V2..Transformer_29: ORA-01861: literal does not match format string.

Can any one of you please let me know what has to be done about this/
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Doesn't Oracle expect a '/' instead of a space in the default date format?
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ArndW wrote:Doesn't Oracle expect a '/' instead of a space in the default date format?
I did try / and -. But both are throwing me the same error
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ArndW wrote:Doesn't Oracle expect a '/' instead of a space in the default date format?
This is the sql that is getting generated

INSERT INTO RNKT0.ATTENDANCE (ATTENDANCE_ID,CUSTOMER_ID,HostMember_ID,Club_ID,Attendance_Date) VALUES (:1,:2,:3,:4,TO_DATE(:5, 'YYYY-MM-DD HH24:MI:SS'))
Can I change this sql somehow?what is the way of changing this generated sql. I what to change theTO_DATE(:5, 'YYYY-MM-DD HH24:MI:SS')). Any help is greatly appreciated
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

dprasanth wrote:
ArndW wrote:Doesn't Oracle expect a '/' instead of a space in the default date format?
This is the sql that is getting generated

INSERT INTO RNKT0.ATTENDANCE (ATTENDANCE_ID,CUSTOMER_ID,HostMember_ID,Club_ID,Attendance_Date) VALUES (:1,:2,:3,:4,TO_DATE(:5, 'YYYY-MM-DD HH24:MI:SS'))
Can I change this sql somehow?what is the way of changing this generated sql. I what to change theTO_DATE(:5, 'YYYY-MM-DD HH24:MI:SS')). Any help is greatly appreciated
I got the above working by just changing the oconv. But if someone can tell me how to work with sql being generated that willl be great.
Post Reply