管理杂谈OA答疑ERP答疑教程搜索

如何得到今天是这个月的第几周



思路是找出该月1号是星期几,推出该周的周末是几号,把两个值放入一个二维数组,依此推出下面几周的起始号和结束号,然后把所在取的号比较得出所在周
<-%
'///////////////////////////////////////////
'function:getweek(date)
'description:取得该日期所在月份的当前周
'para:date要计算的日期
'return:所在周数
'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&"周"
%->



另外一个思路:
<-script type="text/vbs"->
month_week=int(datepart("ww",now)-((datepart("y",now)-datepart("d",now))/7))
alert(month_week)
'datepart("ww",now) 现在是一年第多少周
'(datepart("y",now) 现在是一年第多少天
'datepart("d",now) 现在是这个月第多少天
'年的天数减这个月的天数 除上7就是这个月之前的周数
'总的周数-上个月的周数,表示今天是这个月的多少周
'如果有问题,请高手指点
<-/script->



另一个方法:
<-script type="text/vbs"->
dim month_week
month_week = datediff("ww", dateadd("d",-datepart("d",now), now), now)
'dateadd("d",-datepart("d",now), now) '上个月的月未 与今天对比
alert(month_week)
<-/script->


更多精彩文章浏览...
点击右上角图标分享到朋友圈
官方网站:http://www.clicksun.cn
咨询热线:400-186-1886
服务邮箱:service@clicksun.cn