I am facing a problem
Error converting data type nvarchar to datetime
during inserting a date as a string literal in the format of 26/01/2017
. I am using this code in SQL Server during insert:
CONVERT(DATETIME, @PaymentDate, 104)
Try CONVERT(DATETIME, @PaymentDate, 103)
104
is the German style which uses periods between the numerals, as opposed to slashes. 103
is the British/French style.
See: https://msdn.microsoft.com/en-us/library/ms187928.aspx
I've noticed your question is also tagged with c#.
If you are passing the date from c# to sql server,
Don't pass dates as strings. Pass them as DateTime.
The .Net DateTime
maps directly to SQL Server's DateTime
.
This way, you will not have to deal with the display format at all, since both c# and SQL Server does not store display format in DateTime
.
If you really need to convert the string '26/01/2017'
to date, you should use 103 for your style argument, as already suggested in other answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With