帮我添加01-JAN-13 12.00.00 AM这种格式 [英] help me to add 01-JAN-13 12.00.00 AM this type of format

查看:300
本文介绍了帮我添加01-JAN-13 12.00.00 AM这种格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的列中添加01-JAN-13 12.00.00 AM这种类型的格式..我已将日期时间作为我的数据类型...

I want to add 01-JAN-13 12.00.00 AM this type of format in my columns .. i have take Date time as my datatype ...

推荐答案

在SQL中执行它可能不是一个好主意 - 这种事情通常在演示软件中做得更好,因为它可以告诉用户期望什么类型的格式,如果没有别的月份名称,你指定的格式表示。



但是,如果你必须这样做,那么我建议写一个存储过程(或更好的用户函数)来做转换,因为它需要几个函数调用。最简单的方法是将DateTime值转换为VARCHAR,然后重复使用SUBSTRING函数以获得您想要的格式 - 没有标准格式显示您想要的格式。



我建议你从
It''s probably not a good idea to do it in SQL - this kind of thing is normally better done in the presentation software, because it can tell what type of format the user expects, if nothing else in terms of month names, which your indicated format indicates.

But, if you must do it, then I would suggest to write a stored procedure (or better a user function) to do the conversion, because it is going to require a couple of function calls. The easiest way to do it is to convert the DateTime value to a VARCHAR then use the SUBSTRING function repeatedly to get exactly the format you want - there is not standard format that shows the way you want.

I would suggest you start with
CONVERT(VARCHAR(26), dateValue, 109)

因为这会给你所有您需要的位,但您可以在这里找到更合适的格式: http:// www。 sql-server-helper.com/tips/date-formats.aspx [ ^ ]



样式109会给你

As this gives you all the bits you need, but you may find a more suitable format style here: http://www.sql-server-helper.com/tips/date-formats.aspx[^]

Style 109 will give you

Jan 01 2013 12:00:00.000AM

所以用SUBSTRING分割出你想要的东西并将它们重新排序为一个相对微不足道的事情结果字符串。





正如我所说,最好在演示软件中完成。

So it''s a relatively trivial matter to carve out the bits you want with SUBSTRING and reorder them into a result string.


As I said, it''s better done in the presentation software.


SQL Server按需保存该数据。默认显示为2013-01-01 12.00.00。

您可以使用CONVERT更改它
SQL server saves that data as it wishes. The default display is 2013-01-01 12.00.00.
You can change that by using CONVERT


这篇关于帮我添加01-JAN-13 12.00.00 AM这种格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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