您的位置:程序门 -> vb -> vba



怎么得到某一年中某一周的范围


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎么得到某一年中某一周的范围
发表于:2008-01-10 16:47:00 楼主
怎么得到某一年中某一周的范围。
列如   2008年第一周是   2008/01/01-2008/01/06
发表于:2008-01-10 18:19:421楼 得分:0
第一周应该是1-7吧~~~~
发表于:2008-01-10 18:28:562楼 得分:0
vb.net code
option explicit private type weekinyear firstday as date lastday as date end type private function getdatebyweek(byval intweekinyear as integer) as weekinyear dim intdaycount as integer '一年中有多少天 dim intweekcount as integer '一年中有多少个星期 dim lngday as long if intweekinyear < 1 then exit function intdaycount = 365 ifyeardate) mod 4) = 0 then intdaycount = intdaycount + 1 '如果是闰年,则多加一天 intweekcount = intdaycount \ 7 if (intdaycount mod 7) <> 0 then intweekcount = intweekcount + 1 if intweekinyear > intweekcount then exit function lngday = clngcdateyeardate) & "-1-1")) getdatebyweek.firstday = lngday + (intweekinyear - 1) * 7 getdatebyweek.lastday = lngday + (intweekinyear * 7 - 1) end function private sub form_load() debug.print getdatebyweek(1).firstday, getdatebyweek(1).lastday end sub
发表于:2008-01-10 18:28:583楼 得分:0
vb.net code
option explicit private type weekinyear firstday as date lastday as date end type private function getdatebyweek(byval intweekinyear as integer) as weekinyear dim intdaycount as integer '一年中有多少天 dim intweekcount as integer '一年中有多少个星期 dim lngday as long if intweekinyear < 1 then exit function intdaycount = 365 ifyeardate) mod 4) = 0 then intdaycount = intdaycount + 1 '如果是闰年,则多加一天 intweekcount = intdaycount \ 7 if (intdaycount mod 7) <> 0 then intweekcount = intweekcount + 1 if intweekinyear > intweekcount then exit function lngday = clngcdateyeardate) & "-1-1")) getdatebyweek.firstday = lngday + (intweekinyear - 1) * 7 getdatebyweek.lastday = lngday + (intweekinyear * 7 - 1) end function private sub form_load() debug.print getdatebyweek(1).firstday, getdatebyweek(1).lastday end sub
发表于:2008-01-10 18:29:194楼 得分:0
vb.net code
option explicit private type weekinyear firstday as date lastday as date end type private function getdatebyweek(byval intweekinyear as integer) as weekinyear dim intdaycount as integer '一年中有多少天 dim intweekcount as integer '一年中有多少个星期 dim lngday as long if intweekinyear < 1 then exit function intdaycount = 365 ifyeardate) mod 4) = 0 then intdaycount = intdaycount + 1 '如果是闰年,则多加一天 intweekcount = intdaycount \ 7 if (intdaycount mod 7) <> 0 then intweekcount = intweekcount + 1 if intweekinyear > intweekcount then exit function lngday = clngcdateyeardate) & "-1-1")) getdatebyweek.firstday = lngday + (intweekinyear - 1) * 7 getdatebyweek.lastday = lngday + (intweekinyear * 7 - 1) end function private sub form_load() debug.print getdatebyweek(1).firstday, getdatebyweek(1).lastday end sub
发表于:2008-01-10 18:50:085楼 得分:0
vbscript code
option explicit private sub command1_click() dim y as long '年份 dim w as long '第几周 dim zerodate as date '这年头一天 dim enddate as date '这年最后一天 dim zerowd as long '头一天是星期几 y = clng(text6.text) '年份从文本款输入 w = clng(text7.text) '第几周也从文本款输入 zerodate = cdatecstr(y) & "年1月1日") enddate = cdatecstr(y) & "年12月31日") zerowd = weekday(zerodate) - 1 if zerowd = 0 then zerowd = 7 dim fromday as date dim today as date if w = 1 then fromday = zerodate today = fromday +7 - zerowd) else fromday = zerodate +7 - zerowd) + 1 + (w - 2) * 7 today = fromday + 6 end if if fromday > enddate then msgbox "没有这一周" else if today > enddate then today = enddate msgbox cstr(y) & "年第" & cstr(w) & "周从" & fromday & "" & today end if end sub
发表于:2008-01-10 18:53:246楼 得分:0
sandrer可能领会错了,楼主的意思应该是从周一到周日,如果不满7天就截至到周日吧?
发表于:2008-01-10 21:13:037楼 得分:0
谢谢,各位!!!!!!
特别谢谢!dlyme  


快速检索

最新资讯
热门点击