gpt4 book ai didi

sql-server - 格式化日期以包括星期几

转载 作者:行者123 更新时间:2023-12-04 16:49:38 24 4
gpt4 key购买 nike

我有一个将日期转换为 VARCHAR

的 SQL Server 2012 查询
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 日,星期六?

最佳答案

试试这个:

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

关于sql-server - 格式化日期以包括星期几,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25316816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com