Link to home
Start Free TrialLog in
Avatar of onesegun
onesegunFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Vikas Garg
Vikas Garg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onesegun

ASKER

Fantastic! That works. Thanks