如何在sql server 2005中将dd / mm / yyyy varchar转换为mm / dd / yyyy varchar? [英] How to convert dd/mm/yyyy varchar to mm/dd/yyyy varchar in sql server 2005?

查看:89
本文介绍了如何在sql server 2005中将dd / mm / yyyy varchar转换为mm / dd / yyyy varchar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql server 2005中将dd / mm / yyyy varchar转换为mm / dd / yyyy varchar?

How to convert dd/mm/yyyy varchar to mm/dd/yyyy varchar in sql server 2005?

推荐答案

尝试使用dd / mm中的任何日期/ yyyy

Try this for any date in dd/mm/yyyy
select convert(varchar, convert(datetime, '13/06/2014', 103), 101)



但是,正确的方法是从一开始就使用正确的数据类型,例如date应该是date varchar。


However, the correct way is to use correct data type from the beginning, e.g. date should be date not varchar.


你为什么这样做? :)



处理日期时间,因为数据库中的nvarchar没有任何优势,并且在排序或定义时间范围方面存在巨大的缺点。



请使用正确的数据格式。当数据呈现给用户时,关于日期时间涉及字符串的唯一时刻在表示层上。任何以前使用日期时间作为字符串纯属无意义。
Why do you do that to yourself? :)

Handling datetimes as nvarchar in your database does not present any advantage and has huge drawbacks when it comes to sorting or defining time ranges.

Please use the proper data format. The only moment where a string is involved regarding a datetime is on the presentation layer, when the data is presented to the user. Any former use of a datetime as a string is purely nonsense.


您好,



希望这对您有所帮助。 />


Hi,

Hope this will help you.

SELECT CONVERT(VARCHAR,CONVERT(VARCHAR,GETDATE(),103),101)


这篇关于如何在sql server 2005中将dd / mm / yyyy varchar转换为mm / dd / yyyy varchar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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