Error converting data type nvarchar to datetime SQL Server

0 votes

I encountered this error:

Error converting data type nvarchar to datetime

When inputting a date in the format of 26/01/2017 as a string literal. I'm inserting using this code in SQL Server: 

CONVERT(DATETIME, @PaymentDate, 104)

Can someone please help me with this?

Aug 15, 2022 in Database by Kithuzzz
• 38,000 points
4,037 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Your inquiry is also marked with the c# keyword, I see. Don't pass dates as strings if you are passing dates from C# to a SQL server. Send them as a DateTime. The SQL Server DateTime and the.Net DateTime are the same.
By doing this, you can avoid dealing with the display format entirely because neither c# nor SQL Server store the display format in DateTime.

If you actually need to transform the string "26/01/2017" to date, as mentioned in another response, you should use the style option 103.
answered Aug 15, 2022 by narikkadan
• 86,360 points

edited Mar 5

Related Questions In Database

0 votes
0 answers

SQL Server : Arithmetic overflow error converting expression to data type int

I'm getting this error: msg 8115, level 16, ...READ MORE

Aug 26, 2022 in Database by Kithuzzz
• 38,000 points
1,462 views
0 votes
1 answer
0 votes
0 answers

Login to Microsoft SQL Server Error: 18456

When I try to connect to the SQL ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,000 points
843 views
0 votes
0 answers