如何将默认的日期时间格式转换为长日期时间格式 [英] How to convert default datetime format to long datetime format

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

问题描述

在我的数据库中,日期存储为
2012-02-18 00:00:00.000此格式.
使用以下SQL后
convert(char,datetimefield,103)我正在2012年8月30日

但我想通过以下方式获得它
2012年8月30日,星期四

谁能告诉我哪个sql查询可以帮助我获得上述格式?
预先感谢.

In my datatbase date is stored as
2012-02-18 00:00:00.000 this format.
After using this following SQL
convert(char,datetimefield,103) i am getting 30/08/2012

but i want to get it like this following way
Thrusday,August,30,2012

Can anyone please tell me which sql query helps me to get the above format?
Thanks in advance.

推荐答案


试试这个:
Hi,
Try this:
SELECT DATENAME(DW, GETDATE())+', '+ DATENAME(MONTH, GETDATE())+', '+CONVERT(VARCHAR(2), DAY(GETDATE()))+', '+CONVERT(VARCHAR(12),YEAR(GETDATE()))



--Amit



--Amit


要使用这种格式进行操作,您将需要自定义操作.如果您使用的是SQL Server 2012,则可以使用format命令简化此操作.但是,我假设您尚未使用SQL 2012.在这种情况下,最好的选择是UDF,它允许您以所需的格式传递并以期望的方式获取日期.我见过的最好的例子是Pinal Dave的作品:

http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/ [
To do something with this type of format, you are going to need to do something custom. If you were using SQL Server 2012, there is a format command that makes this easy. However, I''m going to assume you aren''t using SQL 2012 yet. In that case, your best bet is a UDF that allows you to pass in the format you want and get back the date the way you are expecting. The best example I have seen is from Pinal Dave:

http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/[^]

That should do any format you want.


这篇关于如何将默认的日期时间格式转换为长日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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