Page 1 of 1

date conversion error

Posted: Mon Jun 14, 2010 9:02 am
by kavuri
Hi,
I have a job which is reading date as varchar(10). I am trying to convert this into date field by using the following command.

StringToDate(inColumn,"%mm/%dd/%yyyy")

My input data is in the folowing format
1/1/2010

here below is my error.
Fatal Error: Invalid Julian day [date/date.C:1006]

I took the job seperate and tried to read this field alone. Then I am not getting fatal error, but losing the value and following warning is read.
Conversion error calling conversion routine date_from_ustring data may have been lost [transform/tfmop_functions.C:132]

Any help is greatly appreciated.

Thanks
Kavuri

Posted: Mon Jun 14, 2010 9:56 am
by kavuri
Hi,
I had used the work around logic to solve this. If you have any better logic or simple logic to do this let me know.

month1=lnk_odbc_SQLServer.CREATE_DATE['/',1,1]
day1=lnk_odbc_SQLServer.CREATE_DATE['/',2,1]
year1=lnk_odbc_SQLServer.CREATE_DATE['/',3,1]
month=If Len(month1) = 1 then 0:month1 else month1
day=If Len(day1) = 1 then 0:day1 else day1
year=year1
date=month:day:year

target_date=StringToDate(date,"%mm%dd%yyyy")

Thanks
Bhargava

Posted: Mon Jun 14, 2010 11:39 am
by chulett
You are on the right track with padding the single digit months/days with a leading zero so it matches the format mask the conversion function needs. You can simplify what you are doing (using syntax that I don't recall off the top of my head but which has been posted here numerous times) but it still needs to be done.

Posted: Mon Jun 14, 2010 11:51 am
by anbu

Code: Select all

month=Right('00':month1,2)
day=Right('00':day1,2)

Posted: Mon Jun 14, 2010 1:46 pm
by chulett
Thanks... and unless it gets more complicated, you can do all that inside the StringToDate function rather than in several stage variables.

Posted: Tue Jun 15, 2010 12:13 pm
by kavuri
Thanks to both of you.