如何得到今天是这个月的第几周
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[align=left]
[p] 思路是找出该月1号是星期几,推出该周的周末是几号,把两个值放入一个二维数组,依此推出下面几周的起始号和结束号,然后把所在取的号比较得出所在周 [br] <-% [br] '/////////////////////////////////////////// [br] 'function:getweek(date) [br] 'description:取得该日期所在月份的当前周 [br] 'para:date要计算的日期 [br] 'return:所在周数 [br] 'author:愚人(yurensky@hotmail.com) [br] '////////////////////////////////////////// [br] [br] function getweek(strdate) [br] dim strmon,stryear,nweek [br] [br] strdate = formatdatetime(strdate,2) [br] strmon = month(strdate) [br] stryear = year(strdate) [br] strday = day(strdate) [br] nweek = weekday(formatdatetime(stryear&"-"&strmon&"-1",2)) - 1 [br] [br] dim arrrange(5,2) [br] [br] for i = 0 to 4 [br] if i = 0 then [br] arrrange(i,0) = 1 [br] if nweek = 6 then [br] arrrange(i,1) = arrrange(i,0) [br] else [br] arrrange(i,1) = arrrange(i,0) + 6 - nweek [br] end if [br] else [br] arrrange(i,0) = arrrange(i-1,1)+1 [br] arrrange(i,1) = arrrange(i,0) + 6 [br] end if [br] next [br] [br] dim currweek [br] [br] for i = 0 to 4 [br] if arrrange(i,0) <= strday and strday <= arrrange(i,1) then [br] currweek = i + 1 [br] end if [br] next [br] [br] if currweek = "" then [br] currweek = 0 [br] end if [br] [br] getweek = currweek [br] end function [br] [br] [br] 'test [br] dim nweek,cdate [br] cdate = now() [br] nweek = getweek(cdate) [br] [br] response.write cdate & "是"&year(cdate) &"年"&month(cdate)&"月的第"&nweek&"周" [br] %->[/p] [p] [/p] [p]另外一个思路:[br]<-script type="text/vbs"-> [br] month_week=int(datepart("ww",now)-((datepart("y",now)-datepart("d",now))/7)) [br] alert(month_week) [br] 'datepart("ww",now) 现在是一年第多少周 [br] '(datepart("y",now) 现在是一年第多少天 [br] 'datepart("d",now) 现在是这个月第多少天 [br] '年的天数减这个月的天数 除上7就是这个月之前的周数 [br] '总的周数-上个月的周数,表示今天是这个月的多少周 [br] '如果有问题,请高手指点 [br] <-/script->[/p] [p] [/p] [p]另一个方法:[br]<-script type="text/vbs"-> [br] dim month_week [br] month_week = datediff("ww", dateadd("d",-datepart("d",now), now), now) [br] 'dateadd("d",-datepart("d",now), now) '上个月的月未 与今天对比 [br] alert(month_week) [br] <-/script->[/p][/align] 该文章在 2010/6/27 17:40:05 编辑过 |
关键字查询
相关文章
正在查询... |