解析日期时间到SQL Server的最佳方式 [英] Best way to parse DateTime to SQL server
问题描述
我想知道什么是分析一个DateTime对象到您的SQL服务器的最佳方式。
I was wondering what is the best way to parse a DateTime object to your SQL server.
如果您正在生成的SQL在code。
Where you are generating the SQL in code.
我一直使用类似 DateTime.Now.TolongDateString()
并有良好的效果,除了今天在这里我得到了一个错误,这让我觉得。
I have always used something like DateTime.Now.TolongDateString()
and had good results, apart from today where i got a error, and it made me think.
System.Data.SqlClient.SqlException: Conversion failed when converting datetime from character string
那么,什么是每个人的想法和recomendations的,将工作acrss所有SQL Server不管的方式有什么设置..
So what is everyone thoughts and recomendations for a way that will work acrss all SQL server no matter what there setup..
也许像 DateTime.Now.ToString(YYYY / MM / DD)
推荐答案
有只有2个安全的格式
ISO和ISO8601
ISO and ISO8601
ISO =年月月日日
ISO = yymmdd
ISO8601 = YYYY-MM-DD昆明山海棠:MM:SS:嗯(无空格)(注意T)
ISO8601 = yyyy-mm-dd Thh:mm:ss:mmm(no spaces) (notice the T)
另请参见这里:<一href="http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/setting-a-standard-dateformat-for-sql-se">Setting一个标准的日期格式为SQL Server
这篇关于解析日期时间到SQL Server的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!