convert string to date

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
kris_r
Participant
Posts: 32
Joined: Mon Jun 26, 2006 3:09 am
Location: bangalore

convert string to date

Post by kris_r »

Hi,
my input is a string (123179) which needs to be converted to date type.
I tried using iconv and oconv but am still getting date conversion error.
Can someone help me with this..
Thanks,
Krishna.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi Krishna,
What is the format of the string and what is error you getting?
Is it in mmddyy format or some kind of julian date or something like date since..?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kris_r
Participant
Posts: 32
Joined: Mon Jun 26, 2006 3:09 am
Location: bangalore

Post by kris_r »

Hi,
the format is mmddyy.
The error I am getting is "Attempting to convert string value "12/31/79" to Date is Unsuccessful".
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

But it complains that the source is in MM/DD/YY format. What is your target stage?
Use

Code: Select all

 Iconv("Link.Date", "D2/")
to convert it into Date fromate from String. If it is a database stage, you can use To_date() that avaialble in database SQL statement.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kris_r
Participant
Posts: 32
Joined: Mon Jun 26, 2006 3:09 am
Location: bangalore

Post by kris_r »

But the problem is there is no / between the dates in the Input.
It is just MMDDYY. That is the reason i feel it is causing the error.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Have you tried Iconv("Link.Input", "DYMD[2,2,2]")?
Or you can even try the same previous option by concatinating "/" in middle. StageVariable = Link.Input[1,2]:"/":Link.Input[3,2]:"/":Link.Input[5,2], and use this stage variable for conversion.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kris_r
Participant
Posts: 32
Joined: Mon Jun 26, 2006 3:09 am
Location: bangalore

Post by kris_r »

Hi,
I tried creating a stage variable and concatenating '/'. But still I am getting the error message, "Value treated as NULL
Attempt to convert String value "" to Date type unsuccessful".
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Kumar's suggestion of using a ICONV(In.Col,'D2MDY[2,2,2]') will work, as will manually creating a string with separators and then ICONving it.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

ArndW is right. That option will work.
You can also try

Code: Select all

OCONV(ICONV(in.date,"DMDY[2,2,2]":@VM:"MCN"),"D/MDY[2,2,2]")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kris_r
Participant
Posts: 32
Joined: Mon Jun 26, 2006 3:09 am
Location: bangalore

Post by kris_r »

I think I am doing something seriously wrong...
It is still not working...
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I am sure,
for testing purposes just create a simple routine with one arg and paste either mine or kumar's solution there. Test it there. You will see that they both work.
Try loading it to a sequential file. What database are you loading it too.
For most databases, the date format is YYYY-MM-DD
Try this

Code: Select all

OCONV(ICONV(in.date,"DMDY[2,2,2]":@VM:"MCN"),"D-YMD[4,2,2]")
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 »

All too complex. To convert to an internal date all that is needed is

Code: Select all

Iconv(InLink.TheDate, "DMDY")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
nivas
Participant
Posts: 117
Joined: Sun Mar 21, 2004 4:40 pm

Post by nivas »

Hi Kris_r

Could you tell me what is your target database?
thanks
Nivas
Post Reply