在sql server中插入日期为“dd-mm-yyyy”格式 [英] insert date in sql server as "dd-mm-yyyy" format

查看:644
本文介绍了在sql server中插入日期为“dd-mm-yyyy”格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我插入日期并将其插入为yyyy-mm-dd格式

但是我想插入dd-mm-yyyy格式

请告诉我简单编码

如何在sql server中插入日期为dd-mm-yyyy格式

i insert date and its inserted as "yyyy-mm-dd" format
but i want to insert as "dd-mm-yyyy" format
please tell me simple coding for
how to insert date in sql server as "dd-mm-yyyy" format

推荐答案

SQL date是二进制文件字段(无论格式如何都存储二进制值)。

因此,您不能以任何格式在SQL中存储日期 - 只在您的应用程序中以所需格式显示它。

you可以在SQL级别使用它 - http://technet.microsoft.com/en-us/library/ hh213505.aspx [ ^ ]

或应用程序内部的类似内容

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v = vs.110).aspx [ ^ ]
SQL date is a binary field (stores binary value regardless of formatting).
So you do not store date in SQL by any format - only displays it in your desired format in your application.
you may use this at the SQL level - http://technet.microsoft.com/en-us/library/hh213505.aspx[^]
or simething like this inside the application
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]


不要插入日期作为特定格式。应使用适当的Date / DateTime类型存储日期,并将它们存储为通用格式。你应该以特定的格式存储日期是一种常见的误解 - 这是一个不好的做法。什么日期是10/11/2013?是2013年11月10日还是2013年10月11日?通过以通用格式存储日期,可以消除歧义,然后在应该完成的位置执行日期格式化工作 - 在检索后在UI处,可以使其遵循本地日期/时间约定。
Don't insert a date as a specific format. Dates should be stored using the appropriate Date/DateTime types, and they should be stored as a universal format. It's a common misconception that you should be storing dates in a particular format - this is a bad practice to get into. What date was 10/11/2013? Was it the 10th November 2013 or the 11th October 2013? By storing the date in a universal format, you remove ambiguity and you then do the date formatting work at the place it should be done - at the UI after you have retrieved it, where it can be made to follow local date/time conventions.


除非您将其作为字符串(varchar& friends)插入,否则日期未格式化,即内部表示没有格式概念。

可能你在代码中从字符串到日期或从日期到字符串执行了错误的转换。
Unless you are inserting it as a string (varchar & friends) the date is not formatted, i.e. the internal representation has no notion of 'format'.
Probably you are performing a wrong conversion either from string to date or from date to string in your code.


这篇关于在sql server中插入日期为“dd-mm-yyyy”格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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