Obtains the first day of the week of a specified date.

Source: Internet
Author: User

For statistics, you must first obtain the specified date to obtain the first day of the week where the date is located, so as to determine the day to which the week is located.
First read the following code to obtain the date of the current day.

DateTime. Today


If you specify a date instead of the current day, convert it to a date.

DateTime dt = Convert. ToDateTime ();


If you set the specified date to an irregular Date Format String, use DateTime. ParseExact to convert the http://www.cnblogs.com/insus/p/3231007.html.
DateTime has a function that returns the day of the week, such

Dt. DayOfWeek


It will return Sunday, Monday, Tuesday ......
If we convert it into an integer, for example:

() Dt. DayOfWeek


It returns 0, 1, 2 ......
In this case, we can use the. AddDays () method to calculate the start date of the week where the specified date is located:




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.