declare @date datetime;
set @date = getdate()
select datepart(dayofyear,@date) [dayofyear];
select datename(dayofyear,@date) [dayofyear];
--另一种思路:当前日期与上年最后一天差的天数
select datediff(day,dateadd(year,datediff(year,0,@date),-1),@date)[dayofyear]
go
时间: 2024-10-25 08:36:58