Error converting nvarchar to datetime data type

I have the following procedure interface:

Create procedure [dbo].[InsertItemDetails]
    @TimeItemAdded datetime

When I call it this way:

EXEC [dbo].[InsertItemDetails]
     @TimeItemAdded = N'20/07/2012 00:00:00';

I get this error:

Msg 8114, Level 16, State 5
Error converting nvarchar to datetime data type.

+5
source share
4 answers

Depending on your regional settings, the parameter you pass for @TimeItemAddedmay not be recognized.

You must pass the date as:

20120720
+10
source

Use an unambiguous string literal for your date. In this case:

EXEC dbo.InsertItemDetails
    ...
    , @TimeItemAdded = '20120720';

, , , . .

, m/d/y, , , , , , , ..

+2

datetime, http://www.sql-server-helper.com/tips/date-formats.aspx

varchar -, . :

SELECT CONVERT(DATETIME, '20/07/2012 00:00:00', 103)

103 - , .

0

SQL read your date as 7/20/2012which is invalid, you can pass your date objects in a more secure format, yyyy-MM-ddfor example:2012-07-20

0
source

All Articles