I have problem with datetime format for C# and T-SQL.
- C# application is using DD.MM.YYYY HH.mm.SS format
- T-SQL is using MM\DD\YYYY HH.mm.SS format
Obviously T-SQL returns Error converting data type nvarchar to datetime. error.
Is there a way how to check and transform datetime format on SQL side? I would like T-SQL to be able to use DD.MM.YYY format.
Thanks.
Use parameterized queries to avoid this kind of issue.
When you build your SQL as a string to pass to SQL Server, you not only encounter this kind of issue, but may also be exposing yourself to SQL Injection.
With parameterized queries, you would be passing in a
DateTimevalue and the DB library would do the right thing.Formats don’t come into play as they are only used for display.