如何修改日期格式 [英] How to modify date format

查看:100
本文介绍了如何修改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只是想知道,在创建表时有一种方法可以让sql server只接受某些日期格式。



我现在创建了表因为关系已经到位所以再次创建它会很烦人,但是我可以改变表格以接受英国格式的英国格式。



所以类似



ALTER员工

设定格式化日期(DD-MM-YYYY)?





在此先感谢,它可能简单..

它只是让我读起来像MM-DD-YYYY,从长远来看,这将是非常烦人的,因为我的所有插入语句都是以DD-MM-YYY格式格式化的。



谢谢。

So I was just wondering, when creating a table is there a way to make sql server only accept certain date formats.

I've created the table now, and it would be annoying to create it all again as the relationships are already in place, but could i alter the table to accept the british format of the date as im british.

So something like

ALTER Employee
Set Date to format (DD-MM-YYYY)?


Thanks in advance, its probably something simply..
It just saves me reading it like MM-DD-YYYY, which will turn out to be very annoying in the long run and the short run as all my insert statements are formatted in the DD-MM-YYY format.

Thanks.

推荐答案

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



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.


这篇关于如何修改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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