VB. NET obtains the range starting from Sunday according to the year, month, and week

Source: Internet
Author: User

 

Private sub button7_click (byval sender as system. object, byval e as system. eventargs) handles button7.click msgbox ("range:" & getweekperiod (Me. monthid. text, me. weeks. text) (0) & "& getweekperiod (Me. monthid. text, me. weeks. text) (1) end sub private function getweekperiod (byval monthid as string, byval curweeks as integer) as date () dim totalweeks as integer dim y, M as string y = monthid. substring (0, 4) M = monthid. substring (4) dim firstdayofmonth as date = new datetime (Y, M, 1) dim lastdayofmonth as date = new datetime (Y, M, date. daysinmonth (Y, m) dim D as date = firstdayofmonth dim edweek (1) as date dim ed (0) as date dim J as int16 for I as int16 = 0 to date. daysinmonth (Y, m)-1 if D. dayofweek = dayofweek. saturday then redim preserve ed (j) Ed (j) = d j = J + 1 if J = curweeks then if D. adddays (-6) <firstdayofmonth then edweek (0) = firstdayofmonth else edweek (0) = D. adddays (-6) end if edweek (1) = d Return edweek end if d = D. adddays (1) Next totalweeks = ed. length if Ed (ed. length-1) <= lastdayofmonth then totalweeks = totalweeks + 1 end if curweeks> = totalweeks then edweek (0) = ed (ed. length-1 ). adddays (1) edweek (1) = lastdayofmonth end if return edweek end Function

VB. NET obtains the range starting from Sunday according to the year, month, and week selected. The week is defined as from Sunday to Sunday ~ Saturday.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.