sqlserver中的日期时间转换错误(将数据类型nvarchar转换为datetime时出错。) [英] date time converting error in sqlserver( Error converting data type nvarchar to datetime. )

查看:881
本文介绍了sqlserver中的日期时间转换错误(将数据类型nvarchar转换为datetime时出错。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此值传递给datetime参数时有一个日期时间字符串01-10-2013 09:15ص导致错误

i have a datetime string "01-10-2013 09:15 ص" when passing this value to a datetime parameter cause error

Error converting data type nvarchar to datetime.



plz help


plz help

推荐答案

首先,不要将其作为字符串传递 - 将其传递为DateTime通过参数化查询,你不会遇到问题。



问题是SQL期望yyyy-MM-dd格式的日期和非英语字符混淆了它。



将日期作为字符串传递不是一个好主意 - 尽快将它们转换为DateTime值以摆脱用户的任何本地文化信息可能已输入。
Firstly, don't pass it as a string - pass it as a DateTime via a Parametrized Query and you won't get a problem.

The problem is that SQL expects dates in yyyy-MM-dd format, and the non-English characters confuse it.

Passing dates as strings is not a good idea - convert them to DateTime values as soon as possible to get rid of any local Culture information that the user may have entered.


尝试将字符串转换为DateTime。

Try Converting the string to DateTime.
string datetime="01-10-2013 09:15 ص";
DateTime newdatetime = Convert.ToDateTime(datetime);





如果您仍然收到错误,请分享。



If you are still getting the error, Kindly share it.








您尝试做的是直接使用datetime参数传递字符串值。

这不是一个好方法,无论你在sql中使用数据类型,你必须传递相同的值,否则你会面临一些转换问题。

请转换你的字符串值到datetime使用转换。



Hi,


what you try to do is you directly pass string value with datetime parameter.
That is not a good way whatever your using datatypes in sql you must and should to pass the same values otherwise you face some convertion problem.
Please convert your string value to datetime using convert.

string str="01-10-2013 09:15 ص";

DateTime dt1=Convert.ToDateTime(str);


这篇关于sqlserver中的日期时间转换错误(将数据类型nvarchar转换为datetime时出错。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆