格式化日期以包括星期几

时间:2014-08-14 20:14:11

标签: sql-server tsql date datetime sql-server-2012

我有一个SQL Server 2012查询,将日期转换为VARCHAR

SELECT 
    CONVERT(VARCHAR(12), dbo.Download.Date_of_Download, 107) as Date_to_Display,
    dbo.Download.Number_of_Computers
FROM dbo.Download
ORDER BY dbo.Download.Date_of_Download DESC

以下是结果

Date_to_Display Number_of_Computers
-----------------------------------
Aug 14, 2014    240
Aug 13, 2014    519
Aug 12, 2014    622
Aug 11, 2014    2132
Aug 10, 2014    1255
Aug 09, 2014    3240

我如何包括星期几,即2014年8月9日星期六?

1 个答案:

答案 0 :(得分:1)

试试这个:

select datename(dw,getdate())

输出:

------------------------------
Thursday

(1 row(s) affected)

使用您的查询:

SELECT 
    Datename(dw, dbo.Download.Date_of_Download)+', '+CONVERT(VARCHAR(12), dbo.Download.Date_of_Download, 107) as Date_to_Display,
    dbo.Download.Number_of_Computers
FROM dbo.Download
ORDER BY dbo.Download.Date_of_Download DESC