<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>
/**/
/*********************************************************
*作者:水若寒
*QQ:49940396
*Email:shuiruohanilove@sina.com
*日期:2007-4-29
*描述:将指定日期所在月份的所有日期按照周次输出
**********************************************************/
declare @i int -- ---------------------------计数器
declare @curWk int -- -----------------------指定日期在该年的周数
declare @fstWk int -- -----------------------每月一号在该年的周数
declare @fstDay nvarchar ( 10 ) -- -------------每月的第一天
declare @lstDay nvarchar ( 10 ) -- -------------每月的最后一天
declare @tmpDay smalldatetime -- ------------每周日的日期
declare @date smalldatetime -- --------------指定的日期
declare @tmpDay1 smalldatetime -- -----------每周六的日期
set @date = ' 2007-9-1 '
select @fstDay = ( cast ( year ( @date ) as nvarchar ( 4 )) + ' - ' + cast ( month ( @date ) as nvarchar ( 2 )) + ' - ' + ' 1 ' )
set @fstDay = Convert ( nvarchar ( 10 ), cast ( @fstDay as smalldatetime ), 120 )
-- print '本月第一天:'+@fstDay
set @fstWk = datepart (wk, @fstDay )
-- print '本月第一周:'+str(@fstWk)
set @lstDay = Convert ( nvarchar ( 10 ), dateadd (d, - 1 , dateadd (m, 1 , @fstDay )), 120 )
-- print '本月最后一周:'+@lstDay
set @i = 0
-- --找出跟上个月同一周的日期
while ( @i < 8 )
begin
set @tmpDay = dateadd (dd, @i , @fstDay )
set @curWk = datepart (wk, @tmpDay )
if @curWk > @fstWk
begin
-- print @tmpDay
break
end
set @i = @i + 1
end
-- print '本月第二周:'+convert(nvarchar(10),@tmpDay,120)
set @i = 1
-- --找出这个月的日期
while ( @i < 7 )
begin
if ( @i = 1 ) -- --------------如果是第一周,直接输出结果
begin
print ( ' 第 ' + str ( @i ) + ' 周: ' + @fstDay + ' -------- ' + convert ( nvarchar ( 10 ), DateAdd (d, - 1 , @tmpDay ), 120 ))
set @i = @i + 1
end
/**/ /*
*如果周日的日期还在该月内则继续下面的循环
**/
if ( datediff (d, @tmpDay , @lstDay ) >= 0 )
begin
set @tmpDay1 = DateAdd (d, 6 , @tmpDay ) -- ----周六的日期就是周日的日期加六就可以
/**/ /*
*如果周六的日期超过该月最后一天,则直接输出周日跟该月最后一天,否则输出周日跟周六
**/
if ( DateDiff (d, @lstDay , @tmpDay1 ) > 0 ) -- 超过该月最后一天,则直接输出周日跟该月最后一天
begin
print ( ' 第 ' + str ( @i ) + ' 周: ' + Convert ( nvarchar ( 10 ), @tmpDay , 120 ) + ' -------- ' + convert ( nvarchar ( 10 ), @lstDay , 120 ))
end
else -- 输出周日跟周六
print ( ' 第 ' + str ( @i ) + ' 周: ' + Convert ( nvarchar ( 10 ), @tmpDay , 120 ) + ' -------- ' + convert ( nvarchar ( 10 ), @tmpDay1 , 120 ))
end
set @tmpDay = DateAdd (d, 7 , @tmpDay ) -- --算出下周日的日期
if ( datediff (d, @tmpDay , @lstDay ) < 0 ) -- 如果周日的日期超过该月的最后一天,则退出循环
break
set @i = @i + 1
end
*作者:水若寒
*QQ:49940396
*Email:shuiruohanilove@sina.com
*日期:2007-4-29
*描述:将指定日期所在月份的所有日期按照周次输出
**********************************************************/
declare @i int -- ---------------------------计数器
declare @curWk int -- -----------------------指定日期在该年的周数
declare @fstWk int -- -----------------------每月一号在该年的周数
declare @fstDay nvarchar ( 10 ) -- -------------每月的第一天
declare @lstDay nvarchar ( 10 ) -- -------------每月的最后一天
declare @tmpDay smalldatetime -- ------------每周日的日期
declare @date smalldatetime -- --------------指定的日期
declare @tmpDay1 smalldatetime -- -----------每周六的日期
set @date = ' 2007-9-1 '
select @fstDay = ( cast ( year ( @date ) as nvarchar ( 4 )) + ' - ' + cast ( month ( @date ) as nvarchar ( 2 )) + ' - ' + ' 1 ' )
set @fstDay = Convert ( nvarchar ( 10 ), cast ( @fstDay as smalldatetime ), 120 )
-- print '本月第一天:'+@fstDay
set @fstWk = datepart (wk, @fstDay )
-- print '本月第一周:'+str(@fstWk)
set @lstDay = Convert ( nvarchar ( 10 ), dateadd (d, - 1 , dateadd (m, 1 , @fstDay )), 120 )
-- print '本月最后一周:'+@lstDay
set @i = 0
-- --找出跟上个月同一周的日期
while ( @i < 8 )
begin
set @tmpDay = dateadd (dd, @i , @fstDay )
set @curWk = datepart (wk, @tmpDay )
if @curWk > @fstWk
begin
-- print @tmpDay
break
end
set @i = @i + 1
end
-- print '本月第二周:'+convert(nvarchar(10),@tmpDay,120)
set @i = 1
-- --找出这个月的日期
while ( @i < 7 )
begin
if ( @i = 1 ) -- --------------如果是第一周,直接输出结果
begin
print ( ' 第 ' + str ( @i ) + ' 周: ' + @fstDay + ' -------- ' + convert ( nvarchar ( 10 ), DateAdd (d, - 1 , @tmpDay ), 120 ))
set @i = @i + 1
end
/**/ /*
*如果周日的日期还在该月内则继续下面的循环
**/
if ( datediff (d, @tmpDay , @lstDay ) >= 0 )
begin
set @tmpDay1 = DateAdd (d, 6 , @tmpDay ) -- ----周六的日期就是周日的日期加六就可以
/**/ /*
*如果周六的日期超过该月最后一天,则直接输出周日跟该月最后一天,否则输出周日跟周六
**/
if ( DateDiff (d, @lstDay , @tmpDay1 ) > 0 ) -- 超过该月最后一天,则直接输出周日跟该月最后一天
begin
print ( ' 第 ' + str ( @i ) + ' 周: ' + Convert ( nvarchar ( 10 ), @tmpDay , 120 ) + ' -------- ' + convert ( nvarchar ( 10 ), @lstDay , 120 ))
end
else -- 输出周日跟周六
print ( ' 第 ' + str ( @i ) + ' 周: ' + Convert ( nvarchar ( 10 ), @tmpDay , 120 ) + ' -------- ' + convert ( nvarchar ( 10 ), @tmpDay1 , 120 ))
end
set @tmpDay = DateAdd (d, 7 , @tmpDay ) -- --算出下周日的日期
if ( datediff (d, @tmpDay , @lstDay ) < 0 ) -- 如果周日的日期超过该月的最后一天,则退出循环
break
set @i = @i + 1
end