select id,WenHao from GW_LZ where datediff(hh,FSTime,getdate())>24
where datediff(day,'1900-01-01',FSTime)%7+1 not in(6,7)
--2
select id,WenHao from GW_LZ where datediff(hh,FSTime,getdate())>24
where (datepart(dw,FSTime))+@@datefirst-1)%7 not in(0,7)
这是一位朋友给我的,可是,
我的FSTime='2009-1-2 23:52:00'是这个,到现在肯定没超过24小时,今天是周日啊,才过了不到一个小时啊,
可是,我都能吧这条记录查出来啊请各位朋友帮帮忙!!!
where datediff(day,'1900-01-01',FSTime)%7+1 not in(6,7)
--2
select id,WenHao from GW_LZ where datediff(hh,FSTime,getdate())>24
where (datepart(dw,FSTime))+@@datefirst-1)%7 not in(0,7)
这是一位朋友给我的,可是,
我的FSTime='2009-1-2 23:52:00'是这个,到现在肯定没超过24小时,今天是周日啊,才过了不到一个小时啊,
可是,我都能吧这条记录查出来啊请各位朋友帮帮忙!!!
还有FSTime是周五时也要特殊处理.
说错了,只要处理其中一种情况就行了,一般来说处理第二种会相对简单一些,
就是把所有FSTime是周五的记录都当做是两天后的周日的,这样就可以了.
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_WorkDay]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_WorkDay]
GO
--计算两个日期相差的工作天数
CREATE FUNCTION f_WorkDay(
@dt_begin datetime, --计算的开始日期
@dt_end datetime --计算的结束日期
)RETURNS int
AS
BEGIN
DECLARE @workday int,@i int,@bz bit,@dt datetime
IF @dt_begin>@dt_end
SELECT @bz=1,@dt=@dt_begin,@dt_begin=@dt_end,@dt_end=@dt
ELSE
SET @bz=0
SELECT @i=DATEDIFF(Day,@dt_begin,@dt_end)+1,
@workday=@i/7*5,
@dt_begin=DATEADD(Day,@i/7*7,@dt_begin)
WHILE @dt_begin<=@dt_end
BEGIN
SELECT @workday=CASE
WHEN (@@DATEFIRST+DATEPART(Weekday,@dt_begin)-1)%7 BETWEEN 1 AND 5
THEN @workday+1 ELSE @workday END,
@dt_begin=@dt_begin+1
END
RETURN(CASE WHEN @bz=1 THEN -@workday ELSE @workday END)
END
GO