- *********** - Returns in the two days of the two dates and returns to: 1, 2 Table is the first week and the second week, Declare @AA Table (Date DateTime " Weekdays int) Declare @i int set @ i = datediff (day, @ bdate, @ edate) while (@i> = 0) Begin Insert @AA Values (Dateadd (Day, @ i, @ bdate), DatePart (WEEK , dateadd (day, @ i, @ bdate)))))) SET @ i = @ i-1 End Select Weekdays Into #Week from @AA Group by weekdays - *********** Date Sunday, Sunday, Create Function A (@sdate datetime, @ edate datetime) returns int as begin declare @AA table (date datettime) Declare @i int set @ i = datediff (day, @ sdate , @ Edate), (@i> = 0) Begin INSERT @AA Values (dateadd (day, @ i, @ sdate)) set @ i = @ i-1 End select @ i = count (*) from @AA WHERE DatePart (Weekday, Date) Not in (1, 7) Return @i end - such as: SELECT DBO.A ('2004-10-01', '2004-10-11') - Return results 7 - ********** - Enter the beginning of this week, end date declare @firstdayofyear DateTime - year declare @firstdayweekofyear DateTime - The first day of the first week Declare @BDate DateTimedeclare @ Edate DateTime
SELECT @ firstdayofyear = dateadd (yy, datediff (yy, 0, getdate ()), 0) SELECT @firstdayweekofyear = @firstdayofyear - DatePart (dw, @firstdayofyear) 1
SELECT @ edate = dateadd (ww, @ week, @firstdayweekofyear-1) Select @ bdate = dateadd (ww, -1, dateadd (dd, 1, @ edate)) set @Bdate = Convert (DateTime, Convert (Char (10 ), @ Bdate, 101)) Set @EDATE = Convert (DateTime, Convert (Char (10), @ edate, 101))