这个日期是2012年1月18日星期三 [英] this date Wednesday, January 18, 2012 formate

查看:111
本文介绍了这个日期是2012年1月18日星期三的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此日期2012年1月18日星期三formate

解决方案

SQL没有自动生成这种日期格式的任何内容,CONVERT函数受限制它可以处理的样式数量: http://www.w3schools.com/sql/func_convert.asp [ ^ ]



如果你想要那种特定的格式,那么你要么必须编写自己的函数(可能需要使用CONVERT几次然后提取子字符串),要么在你的演示软件中进行(可能有更好的格式范围)


从SQL Server 2012开始,有一个名为FORMAT()的内置函数可以满足这种要求。

示例:

  SELECT 格式(GETDATE(),'  D'  -    2015年1月8日,星期四 



参考 -

SQL Server的FORMAT()函数 [ ^ ]



对于早于2012年的SQL Server版本,你可以创建你自己的工作如



  SELECT  DATENAME(WEEKDAY, GETDATE())+ ' ,' + DATENAME(MONTH,GETDATE())+ ' ' + DATENAME(DD,GETDATE())+ ' ,' + DATENAME(年,GETDATE())  -    2015年1月8日,星期四 



您可以为此创建用户定义的函数,以便重用代码。如果您需要帮助,请告诉我。



希望有帮助:)


正如Griff所说,sql没有任何日期格式(2012年1月18日星期三)。

但你可以尝试这样,

 声明  @ Day_of_week   nvarchar (max)= '  2012年1月18日'; 
选择 DATENAME(WEEKDAY, @ Day_of_week )+ ' ,' + @ Day_of_week as Day_of_Week


this date Wednesday, January 18, 2012 formate

解决方案

SQL doesn't have anything for generating that kind of date format automatically, the CONVERT function is restricted in the number of styles it can cope with: http://www.w3schools.com/sql/func_convert.asp[^]

If you want that specific format, then you will either have to write your own function (probably using CONVERT a couple of times and then extracting the substrings) or do it in you presentation software (which is likely to have a better range of formats available)


Since SQL Server 2012, there is an inbuilt function called FORMAT() is there for this kind of requirement.
Example:

SELECT FORMAT(GETDATE(), 'D') --Thursday, January 8, 2015


Reference-
SQL Server's FORMAT() function[^]

For SQL Server version earlier than 2012, you can create your own work around like

SELECT DATENAME(WEEKDAY,GETDATE())+', '+DATENAME(MONTH,GETDATE())+' '+DATENAME(DD,GETDATE())+', '+DATENAME(YEAR,GETDATE()) --Thursday, January 8, 2015


You can create an user defined function for this for reuse of the code. In case you need help on that, please let me know.

Hope that helps :)


As Griff said,sql does not have any date format like (Wednesday, January 18, 2012).
but you can try like this,

declare @Day_of_week nvarchar(max)='18 Jan 2012';
select DATENAME(WEEKDAY,@Day_of_week)+','+@Day_of_week as Day_of_Week


这篇关于这个日期是2012年1月18日星期三的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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