Date format problem

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

vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Date format problem

Post by vsi »

Hi,
my source is flat file and target is Oracle iam trying to convert my date format: 20060815 to 15-AUG-2006 by using Oconv and iconv functions as:

oconv(iconv(date, "DYMD"), "D-DMY[2,A3,4]")

but iam getting Error as: Attempt to convert String value " 15-AUG-2006 " to Timestamp type unsuccessful
anybody please answer me.

Thanks in advance
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

What are your datatypes in source and target? In Btw, try this

Code: Select all

Oconv(Iconv(date[1,4]:'-' :date[5,2]:'-':date[7,2],"DYMD"),"D-DMY[2,A3,4]") 
Kris

Where's the "Any" key?-Homer Simpson
thumsup9
Charter Member
Charter Member
Posts: 168
Joined: Fri Feb 18, 2005 11:29 am

Post by thumsup9 »

FYI you will have to validate your source date before converting it. If your source date can be NULL or Empty or some invalid date then you need to handle that before conversion.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Date format problem

Post by chulett »

vsi wrote:but iam getting Error as: Attempt to convert String value " 15-AUG-2006 " to Timestamp type unsuccessful
That would be because the format you chose is not appropriate for a Timestamp datatype. You would need to convert it to YYYY-MM-DD format, not DD-MON-YYYY. Technically, the OCI stage is expecting this for a Timestamp:

Code: Select all

YYYY-MM-DD HH24:MI:SS
-craig

"You can never have too many knives" -- Logan Nine Fingers
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Post by vsi »

Hi, Kris
source datatype is: varchar, Target datatype: date

Thanks
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

That explains it , Chulett is correct...the format that you converted in is not compatible for the target stage..
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

See if this ICONV works. DOnt have access to DataStage so cannot test it at the moment. Try it

Code: Select all

OCONV(ICONV(Date, "DYMD[4,2,2]": @VM : "MCN"),"D-DMY[2,A3,4]")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your date is OK, but it's not a timestamp. Append " 00:00:00" to it using concatenation.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry, but that date is not ok if the field has been declared as a Timestamp in the job and the stage is generating the DML. And I've already posted what the stage expects in that case.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

vsi wrote:Hi, Kris
source datatype is: varchar, Target datatype: date

Thanks
Ok, now i am confused. The OP says the target type is 'date', Craig you say its timestamp. What is it???
:roll:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The error message mentioned "convert to timestamp".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Which typically means that the Oracle target type is a DATE field with the DataStage datatype declared as a Timestamp, the default when importing metadata via the OCI plug-in. With that combination and generated SQL, the stage wraps a TO_DATE around the field:

Code: Select all

TO_DATE(YourField,'YYYY-MM-DD HH24:MI:SS')
Now, if you define your DataStage job's datatype as a Date, the generated DML is different:

Code: Select all

TO_DATE(YourField,'DD-MON-YY')
The OP would need to clarify what their situation is. The moral of the story is the fact that you need to be cognizant of how the OCI stages work for the various datatypes - especially DATE fields - and deliver the data in whatever format the stage is expecting. BTW, this is spelled out in the .pdf documentation for the stage.

[soapbox]
In my opinion, it's best to adopt a standard methodology that all developers use when dealing with Oracle dates, one that leverages the behaviour of the stage. Enforce that via a series of Oracle date handling routines. I don't believe any approach that treats dates as Varchars and relies on the NLS_DATE format of the database is a valid approach and is fraught with peril. One that takes advantage of the stage and standardizes on an ISO Standard Timestamp format - including a zero timestamp when the date "doesn't have" a time portion - is the only way to go. It will consistantly work regardless of the NLS_DATE format of the Oracle database and make your DATE field woes a thing of the past.
[/soapbox]
-craig

"You can never have too many knives" -- Logan Nine Fingers
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Post by vsi »

Hi, craig

i have tried this: in 7.5 it works fine:
oconv(iconv(DSLink3.HIREDATE, "DYMD"), "D-YMD[4,2,2]")
with datatype: Timestamp

but its not working with 4.2 version, can you suggest in this.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well... 4.2 is pretty old so I don't remember all the gory details about how it worked back then. Explain what 'not working' means. What SQL does the stage generate, what errors do you get, etc.
-craig

"You can never have too many knives" -- Logan Nine Fingers
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Post by vsi »

iam getting the error:
Attempt to convert String value " 2006-08-28 " to Timestamp type unsuccessful

Thanks
Post Reply