且构网

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

如何修改日期格式

更新时间:2023-01-29 19:28:46

如果要在插入数据时解决问题,请使用:设置日期格式 [ ^ ]插入语句之前;)



If you want to resolve problem while inserting data, please use: SET DATEFORMAT[^] before insert statement ;)

SET DATEFORMAT dmy;
INSERT ...


听起来如果您正在使用DATE或表中的DATETIME数据类型然后调用端的代码不使用参数,而是通过将值直接连接到SQL语句来进行调用。这会导致这个确切的问题。



如果是这种情况,我的建议是应该更改调用代码。如果正确使用了这些参数,则SQL Server驱动程序会注意将日期发送到数据库并以适当的格式从中读取。
It sounds that if you're using DATE or DATETIME data types in the table then the code at the calling side is not using parameters but makes the calls by concatenating values directly into the SQL statement. This would cause this exact problem.

If that is the case, my advice is that the calling code should be changed. If the parameters are used correctly then the SQL Server driver takes care that the date is sent to the database and read from it in proper format.