SSIS: Conversion failed when converting date and/or time from character string

Hi All,

I have a problem.

I'm trying to insert a date value (which is a sting) into a date column (which is a date data type). The date is read from the file creation property of a file using the script task in C# as follows:

strFileDate = (FileObject.CreationTime.ToShortDateString)
        strFileTime = (FileObject.CreationTime.ToShortTimeString)

Open in new window


I pass the date and time to variables in SSIS and then from there I use the SQL task to try to insert the date and time variables into the SQL server table as follows:

INSERT INTO ag_opendatetime (OpenDate, OpenTime) SELECT '', ''

Open in new window


In the SQL task in Expressions I have set the following to read the values of the variables as follows:

"INSERT INTO ag_opendatetime (OpenDate, OpenTime) SELECT '"+ @[User::FileDate]+"', '"+@[User::FileTime] +"'"

Open in new window


Eventually I get the error
SSIS: Conversion failed when converting date and/or time from character string

I've tried every convert(date, cast( etc and it doesn't work. How can I make SQL server accept the string date and or time values?

Thanks,

Shaye
onesegunAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

In place of passing variable in the Execute SQL Task you can Write insert query like this

INSERT INTO [dbo].[CallData]
           ([insertProcess]
           ,[insertDTTM])
     VALUES
           (?,?)
And then Map the parameter it will work.

I tested this and there is no issue with it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
onesegunAuthor Commented:
Fantastic! That works. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.