且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将默认的日期时间格式转换为长日期时间格式

更新时间:2023-02-12 22:20:23


试试这个:
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.