首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

Sql 中怎么计算两日期间的天数

2011-12-26 
Sql 中如何计算两日期间的天数我想将日期转化为第n个工作日(起始时间为3/1/2006),工作日不包含周六和周日

Sql 中如何计算两日期间的天数
我想将日期转化为第n个工作日(起始时间为3/1/2006),工作日不包含周六和周日以及一些特定的假期(holiday表给出)。请问有没有办法

[解决办法]
select datediff(day, '2007-01-01 ',getdate())-(select count(1) from holiday where dt <getdate())

类似这样
[解决办法]
假如你的有可能和周六和周日重叠那么这样
declare @stasun int,@add int
set @stasun =datediff(day, '2007-03-01 ',getdate())
set @add=case when (@stasun % 7)=2 then 1 when (@stasun % 7)> 2 then 2 end
select @stasun-(select count(1) from holiday where datediff(day, '2007-03-03 ',dt) % 7 > =2)- (@stasun /7)*2 -@add

热点排行