如何得到今天是這個月的第幾周
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
[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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |