gpt4 book ai didi

SQL - 获取月份/季度的数字日

转载 作者:行者123 更新时间:2023-12-02 10:33:58 25 4
gpt4 key购买 nike

使用 SQL Server 2005:

如何在查询中获取月份中的日期和季度中的日期?

DECLARE @DATE DATETIME
SET @DATE = GETDATE()

SELECT DATEPART(dy, @DATE) AS DayOfYear
--, <something> AS DayOfQuarter
--, <something> AS DayOfMonth
, DATEPART(dw, @DATE) AS DayOfWeek

提前致谢!

最佳答案

DECLARE @DATE DATETIME
SET @DATE = GETDATE()

SELECT DATEPART(dy, @DATE) AS DayOfYear
, DATEDIFF(d, DATEADD(qq, DATEDIFF(qq, 0, @DATE), 0), @DATE) + 1 AS DayOfQuarter
, DAY(@Date) AS DayOfMonth
, DATEPART(dw, @DATE) AS DayOfWeek

关于SQL - 获取月份/季度的数字日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5461030/

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