且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将任何日期时间格式转换为sql server标准日期时间格式?

更新时间:2023-01-28 09:26:50

不要将日期作为字符串存储在数据库中!



(请想象Bart Simpson在黑板上写这100次;-))



按原样存储它们:日期或日期时间。那么你就不会有任何国家问题(关于数据库)。看看这里:日期和时间类型 [ ^ ]



In如果您正在使用C#或VB.NET中的SQL服务器:您需要使用SQL参数将DateTime值发送到SQL服务器而不将其误认为字符串:SqlParameter Class(System.Data.SqlClient) [ ^ 一>

Hi,

I am facing problems while inserting other countries datetime formats except US in sql table. I am passing datetime value from my application by using DateTime.Now which takes current system datetime.
So plz suggest me how to convert the datetime format of any country into standard sql datetime format.


Thanks in advance.

What I have tried:

I changed default language to spanish in security>logins>user>properties>Default language to spanish.

Don't store dates as strings in a database!

(Please imagine Bart Simpson writing this 100 times on a chalkboard ;-) )

Store them as what they are: Date or DateTime. Then you won't have any country issues at all with that (concerning the database). Take a look here: Date and Time Types[^]

In case you're using SQL server from C# or VB.NET: You need to use SQL-parameters in order to "send" the DateTime-value to SQL-server without mistreating it as a string: SqlParameter Class (System.Data.SqlClient)[^]