[SQL Server]Conversion failed when converting date and/or time from character string.

  • hi there, hope in your help.

    I need convert the nvarchar(255) field [myDates] to Datetime.

    I tried this query, but I've the error.

    I'm not sure where to go from here. Any help would be greatly appreciated.

    SELECT

    CONVERT (

    DATETIME,

    [DB1].[tkt].[myDates],

    103

    )

    FROM

    [DB1].[tkt];

    [Err] 22007 - [SQL Server]Conversion failed when converting

    date and/or time from character string.

    DROP TABLE [DB1].[tkt]

    GO

    CREATE TABLE [DB1].[tkt] (

    [myDates] nvarchar(255) NULL

    )

    GO

    DBCC CHECKIDENT(N'[DB1].[tkt]', RESEED, 3806913)

    GOINSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:34');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:28');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:38');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:28');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:29');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:27');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 11:19');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:27

    15/02/2013 10:27');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:33');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:28');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:32');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:27');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:45');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:27');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:39');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:26');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:31');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:26');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:39');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:26');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:44');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:26');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:26');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 11:49');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:31

    15/02/2013 10:31');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:24');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:30');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:25');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:25');

    GO

    INSERT INTO [tkt] ([myDates]) VALUES ('15/02/2013 10:24');

    GO

  • Seems you have a couple records with two dates in there.. fix those and it works fine

  • thanks a lot

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply