Obtain the Monday and Sunday of the week.

Source: Internet
Author: User

# Region obtain Monday of the week
/// <Summary>
/// Obtain the Monday date of the week
/// </Summary>
/// <Returns> </returns>
Public static string getthisweekmonday ()
{
Datetime date = datetime. now;
Datetime firstdate = system. datetime. now;
Switch (date. dayofweek)
{
Case System. dayofweek. Monday:
Firstdate = date;
Break;
Case System. dayofweek. Tuesday:
Firstdate = date. adddays (-1 );
Break;
Case System. dayofweek. Wednesday:
Firstdate = date. adddays (-2 );
Break;
Case System. dayofweek. Thursday:
Firstdate = date. adddays (-3 );
Break;
Case System. dayofweek. Friday:
Firstdate = date. adddays (-4 );
Break;
Case System. dayofweek. Saturday:
Firstdate = date. adddays (-5 );
Break;
Case System. dayofweek. Sunday:
Firstdate = date. adddays (-6 );
Break;
}
Return firstdate. tostring ("yyyy-mm-dd ");
}
# Endregion

# Region obtain Sunday of the week
/// <Summary>
/// Obtain the Sunday date of the week
/// </Summary>
/// <Returns> </returns>
Public static string getthisweeksunday ()
{
Datetime date = datetime. now;
Datetime lastdate = system. datetime. now;
Switch (date. dayofweek)
{
Case System. dayofweek. Monday:
Lastdate = date. adddays (6 );
Break;
Case System. dayofweek. Tuesday:
Lastdate = date. adddays (5 );
Break;
Case System. dayofweek. Wednesday:
Lastdate = date. adddays (4 );
Break;
Case System. dayofweek. Thursday:
Lastdate = date. adddays (3 );
Break;
Case System. dayofweek. Friday:
Lastdate = date. adddays (2 );
Break;
Case System. dayofweek. Saturday:
Lastdate = date. adddays (1 );
Break;
Case System. dayofweek. Sunday:
Lastdate = date;
Break;
}
Return lastdate. tostring ("yyyy-mm-dd ");
}
# Endregion

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.