Date conversion

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

Post Reply
mohanraj
Participant
Posts: 48
Joined: Sat Mar 25, 2006 12:40 am
Location: bangalore

Date conversion

Post by mohanraj »

hi to all

My source data is from flat files and in that one column contains DATE in these fromats
20051121 and 2005521
and i want to put in oracle OCI in its default format
i tried it by doing Oconv and Iconv.But i could able to convert only one type that is 20051121.I can convert other also in the same way but both the types are in same column only.

So my question is if the incoming data in a column contains 3-4 formats of DATE type how can i convert it to one single format.

Whether i have to apply one condition for each type and OR between them.

How can i do it

Thanks in advance

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

Post by chulett »

What "3-4 formats of DATE" do you speak? You've only shown one.

If you really need to handle that, a custom routine is in order. One that attempts to detect the incoming format and handles it accordingly, whatever that may mean.

Please post what you've tried so far.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

How could you distinguish 2005111 from 2005111? Is it 2005-01-11 or 2005-11-01?
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

As Craig requested, please provide all possible formats that you can get. This way it will be easier to us to point you in the right direction, even a possible solution.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yerk... hope nobody is sending dates as ambiuous as that. I've seen ones where the month may not include a leading zero but the day would always, so the answer in that case would be 2005-01-11.

But it does complicate things... for no good reason...
-craig

"You can never have too many knives" -- Logan Nine Fingers
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
There are several options.
Recap:
You have a file with a month that doesn't have leading zero in single digit months; i.e. 20051121 and 2005521

So you need to find a way that works for both types, or conditionally convert the apropriate type after you verify which one you have

one way might be using a routine to inshure a fixed format such as this:

Code: Select all

year = Arg1[1,4]
monthLen = Len(Arg1) - 6
month = Arg1[5,monthLen]
If monthLen = 1 Then month = "0" : month
days = Arg1[5 + monthLen,2]
Ans = year : month : days
You can modify it to include any conversions you might need as well.

If you have also varying days with no leading zeros you might be in a bit of a problem, since you have no way to differ first of November 2005111 from January 11th 2005111 and similar dates.


IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
mohanraj
Participant
Posts: 48
Joined: Sat Mar 25, 2006 12:40 am
Location: bangalore

My problem is exactly what roy analysed

Post by mohanraj »

hi roy

My problem is in one of my column one format of date is yyyymmdd
and one more format is without leading month that is like yyyymdd.

Then how can i convert it into dd-mon-yyyy format
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Iconv() and Oconv(). But first you need a guaranteed mechanism for standardising your date format, adding a leading zero to the month where necessary. For example

Code: Select all

If Len(TheDate) = 7 Then Left(TheDate,4) : "0" : Right(TheDate,3) Else TheDate
Apply an Iconv() function to this, specifying that the date components are in year, month, day order.

Code: Select all

Iconv(result1, "DYMD")
Apply an Oconv() to that result, to generate the date in your required format; in your case with "-" as the delimiter character, a two digit day, a three-character alphabetic abbreviated month name and a four digit year.

Code: Select all

Oconv(result2, "D-DMBY[2,A3,4]")
Putting it all together you get

Code: Select all

Oconv(Iconv(If Len(InLink.TheDate) = 7 Then Left(InLink.TheDate,4) : "0" : Right(InLink.TheDate, 3), "DYMD"), "D-DMBY[2,A3,4]")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jvr_3jv
Participant
Posts: 2
Joined: Tue Jun 20, 2006 9:00 am

Re: Date conversion

Post by jvr_3jv »

Hi Raju,

Try with this following code and the Inlink.Date is the in column name
data type is varchar

if len(Inlink.Date)=8 then Inlink.Date[7,2]:"-":Inlink.Date[5,2]:"-":Inlink.Date[1,4] else Inlink.Date[6,2]:"-":"0":Inlink.Date[5,1]:"-":Inlink.Date[1,4]

before passing to the outlink u need to use the following function which will convert the varchar format to Date format

StringToDate(StageVar,"%dd-%mm-%yyyy")

Please let me know any confusion on this.
Regards,
Venkat :D
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Venkat's solution will not work in a server job because the StringToDate() function is only available in parallel jobs. :oops:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
newtier
Premium Member
Premium Member
Posts: 27
Joined: Mon Dec 13, 2004 5:50 pm
Location: St. Louis, MO

Post by newtier »

ray.wurlod wrote:Venkat's solution will not work in a server job because the StringToDate() function is only available in parallel jobs. :oops: ...
Or omit the function call, and in the ORAOCI stage make sure the generated SQL (or you add in user-defined SQL) has the TO_DATE() function for that column.
Rick H
Senior Consultant
Post Reply