在sql server 2008中以'dd / MM / yyyy'存储日期 [英] storing a date in 'dd/MM/yyyy' in sql server 2008

查看:67
本文介绍了在sql server 2008中以'dd / MM / yyyy'存储日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以''dd / MM / yyyy''的格式插入日期。但是在数据库中它以下列格式存储''MM / dd / yyyy''。我应该如何解决这个pblm?

I inserting a date in the format of ''dd/MM/yyyy''.But in database it is storing in the following format ''MM/dd/yyyy''.how should i solve this pblm?

推荐答案

日期将始终以s / s服务器中的MM / dd / yyyy格式存储。如果你想用dd / MM / yyyy格式尝试转换它。

例如

Date will always be stored in MM/dd/yyyy format in sql server. If you want it in dd/MM/yyyy format try converting it.
For example
SELECT convert(varchar, getdate(), 103)  --dd/mm/yyyy





退房

如何格式化datetime& Sql Server 2005中的日期 [ ^ ]

SQL Server日期格式 [ ^ ]


最好的方法是将日期列数据类型保存为日期时间,每当您想从数据库中检索数据时,您可以以不同的格式获取ex。你也可以试试其他没有。还有

The best ways is keep date column datatype as datetime and whenever you want to retrieve data from database then you can fetch in different format for ex. you can also try some other no. also
SELECT convert(varchar, getdate(), 103)<pre lang="sql">--08/01/2013 --dd/MM/yyyy
SELECT convert(varchar, getdate(), 105) --08-01-2013 --dd-MM-yyyy
SELECT convert(varchar, getdate(), 109) --Jan  8 2013  2:24:17:140PM</pre>


你不是。如果您将其存储为日期,那么您看到的是渲染细节,数据库根本不使用任何格式,它只是在显示它时以显示它的格式显示,基于服务器的区域设置。如果您的服务器在美国并且您想要显示dd / mm / yyyy,请使用DateTime类上的ToString方法更改有意义的位置的格式,即表示层。
You don''t. If you store it as a date, then what you see is a rendering detail, the database is not using any format at all, it''s just showing it in a format when it shows it, based on the locale of the server. If your server is in the US and you want to show dd/mm/yyyy, use the ToString method on the DateTime class to change the format in the place that makes sense, the presentation layer.


这篇关于在sql server 2008中以'dd / MM / yyyy'存储日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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