sql 返回 第幾周

2022-07-20 01:21:15 字數 1752 閱讀 9150

--孕婦預產期 週數

/****** 物件: userdefinedfunction [dbo].[f_crm_getedcweek] 指令碼日期: 07/27/2020 17:24:52 ******/

set ansi_nulls on

goset quoted_identifier on

goalter function [dbo].[f_crm_getedcweek](@edc datetime)

returns int

asbegin

declare @edcweek int,@today datetime,@ledc datetime

set @edcweek = 0

set @today = convert(char(10),getdate(),126)

if @edc >= @today

begin

set @ledc = @edc - 280;

set @edcweek = abs(datediff(day,@today,@ledc) / 7);

endreturn @edcweek

end

----返回星期名字

alter function [dbo].[f_pre_getweekname](@date datetime,@weekname varchar(10) = '',@flag int = 0)

returns varchar(10)

asbegin

declare @weekid int

declare @myweekname varchar(10)

if @flag = 0

begin

set @weekid = datepart(w,@date);

if @weekid = 7 set @myweekname = '星期六'

else if @weekid = 1 set @myweekname = '星期天'

else if @weekid = 2 set @myweekname = '星期一'

else if @weekid = 3 set @myweekname = '星期二'

else if @weekid = 4 set @myweekname = '星期三'

else if @weekid = 5 set @myweekname = '星期四'

else if @weekid = 6 set @myweekname = '星期五'

endelse if @flag = 1

begin

if @weekname = '星期六' set @weekid = 7

else if @weekname = '星期天' set @weekid = 1

else if @weekname = '星期一' set @weekid = 2

else if @weekname = '星期二' set @weekid = 3

else if @weekname = '星期三' set @weekid = 4

else if @weekname = '星期四' set @weekid = 5

else if @weekname = '星期五' set @weekid = 6

end

if @flag = 1 set @myweekname = cast(@weekid as varchar(10))

return @myweekname

end

當前第幾周

private int week datetime day return w 上面的測試正確。int currentweek 0 構造當前月的1號 datetime dd new datetime datetime.now.year,datetime.now.month,1 獲得當前月1號是乙個星期...

一年的第幾周怎麼算 求當天是本月的第幾周 ahk

在群裡遇到一的問題 求當天是本月的第幾周?用 解決。首先要確定 第幾周 的含義,有以下幾中 1 7號算第一周,其它類推 週日到週六算一周 周一到週日算一周。問題的複雜在於,用2 3的標準來算,還要看每月1號到週末的幾天,算不算一周?因為可能不滿7天。的標準是 4天以上算一周,3天以下不算。歸納如下 ...

獲取每年的第幾周集合

public class dateutil else if time.length 110 date date new date dateformat sdf new dateformat yyyy mm dd hh mm ss try catch exception e string last12...