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

Question
-
I am trying to insert a datetime value (02/04/0000 00:23:14.713) into a table column with datatype "DateTime2" . I am using SQL Server 2012.
SQL Code:
insert into [TrcLauraFeed]([ConfirmDate]) values (cast('02/04/0000 00:23:14.713' as datetime2))
Error message: Conversion failed when converting date and/or time from character string.
Table Details :
TableName - [TrcLauraFeed]
ColumnName - [ConfirmDate]
ColumnDatatype - DateTime2
Please tell how to do this. Thanks
Thanks, Balaji NS
- Edited by Balaji666 Friday, August 16, 2013 11:36 AM Added details
Friday, August 16, 2013 11:35 AM
Answers
-
- Edited by Olaf HelperMVP Friday, August 16, 2013 11:39 AM typo
- Proposed as answer by Sergio S Arias Friday, August 16, 2013 1:17 PM
- Marked as answer by Balaji666 Friday, August 23, 2013 2:27 PM
Friday, August 16, 2013 11:39 AM
All replies
-
- Edited by Olaf HelperMVP Friday, August 16, 2013 11:39 AM typo
- Proposed as answer by Sergio S Arias Friday, August 16, 2013 1:17 PM
- Marked as answer by Balaji666 Friday, August 23, 2013 2:27 PM
Friday, August 16, 2013 11:39 AM -
Look like problem with year,
select '02/04/0000 00:23:14.713',CAST( '02/04/0001 00:23:14.713' as datetime2)
Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.
Friday, August 16, 2013 11:41 AM -
See datetime2 (Transact-SQL) =>
Date range
0001-01-01 through 9999-12-31
Olaf Helper
[ Blog] [ Xing] [ MVP]Friday, August 16, 2013 11:48 AM -
Thanks for the response.
Let me put my requirement more specific.
But i am doing a data migration from Sybase to SQLServer2012 using SSMA.
A column in Source db( Sybase) has datatype datetime and the same in Target DB(SQLServer) has datatype datetime2.
All rows are getting migrated except a row which has column value '02/04/0000 00:23:14.713' , value since SQLServer doesnt allow year 0000.
I am not able to insert this row manully because of the same problem as the column in target db(SQLServer) is defined as Datetime2
insert into [TrcLauraFeed]([ConfirmDate]) values (cast('02/04/0000 00:23:14.713' as datetime2))
Error message: Conversion failed when converting date and/or time from character string.
Please tell how to do this. Thanks
Thanks, Balaji NS
Tuesday, August 20, 2013 10:52 AM