[align=left]
思路是找出該月1號(hào)是星期幾,推出該周的周末是幾號(hào),把兩個(gè)值放入一個(gè)二維數(shù)組,依此推出下面幾周的起始號(hào)和結(jié)束號(hào),然后把所在取的號(hào)比較得出所在周
<-%
'///////////////////////////////////////////
'function:getweek(date)
'description:取得該日期所在月份的當(dāng)前周
'para:date要計(jì)算的日期
'return:所在周數(shù)
'author:愚人(yurensky@hotmail.com)
'//////////////////////////////////////////
function getweek(strdate)
dim strmon,stryear,nweek
strdate = formatdatetime(strdate,2)
strmon = month(strdate)
stryear = year(strdate)
strday = day(strdate)
nweek = weekday(formatdatetime(stryear&"-"&strmon&"-1",2)) - 1
dim arrrange(5,2)
for i = 0 to 4
if i = 0 then
arrrange(i,0) = 1
if nweek = 6 then
arrrange(i,1) = arrrange(i,0)
else
arrrange(i,1) = arrrange(i,0) + 6 - nweek
end if
else
arrrange(i,0) = arrrange(i-1,1)+1
arrrange(i,1) = arrrange(i,0) + 6
end if
next
dim currweek
for i = 0 to 4
if arrrange(i,0) <= strday and strday <= arrrange(i,1) then
currweek = i + 1
end if
next
if currweek = "" then
currweek = 0
end if
getweek = currweek
end function
'test
dim nweek,cdate
cdate = now()
nweek = getweek(cdate)
response.write cdate & "是"&year(cdate) &"年"&month(cdate)&"月的第"&nweek&"周"
%->
另外一個(gè)思路:
<-script type="text/vbs"->
month_week=int(datepart("ww",now)-((datepart("y",now)-datepart("d",now))/7))
alert(month_week)
'datepart("ww",now) 現(xiàn)在是一年第多少周
'(datepart("y",now) 現(xiàn)在是一年第多少天
'datepart("d",now) 現(xiàn)在是這個(gè)月第多少天
'年的天數(shù)減這個(gè)月的天數(shù) 除上7就是這個(gè)月之前的周數(shù)
'總的周數(shù)-上個(gè)月的周數(shù),表示今天是這個(gè)月的多少周
'如果有問題,請(qǐng)高手指點(diǎn)
<-/script->
另一個(gè)方法:
<-script type="text/vbs"->
dim month_week
month_week = datediff("ww", dateadd("d",-datepart("d",now), now), now)
'dateadd("d",-datepart("d",now), now) '上個(gè)月的月未 與今天對(duì)比
alert(month_week)
<-/script->
[/align]
該文章在 2010/6/27 17:40:05 編輯過