ASP. For the current time, this week, last week, next week, Monday, Sunday, day

Source: Internet
Author: User


This week, 1st, returns the result format: 2014-5-5 0:00:00

public static DateTime Getmondaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (1-today). Date;

}

Else

{

Return dt. AddDays ( -6-today). date;//If today is Sunday, get the week 1st period is the date of the next Monday, so subtract 7 days

}

}

This Sunday day

public static DateTime Getsundaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (7-today). Date;

}

Else

{

Return dt. AddDays (-today). date;//If today is Sunday, get the Sunday date is the date of next Sunday, so subtract 7 days

}

}

Last 1st

public static DateTime Getlastmondaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (-today-6). Date;

}

Else

{

Return dt. AddDays (-TODAY-13). date;//If today is Sunday, get the date of last Monday is the date of this week Monday, so subtract 7 days

}

}

Last week Giges period

public static DateTime Getlastsundaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (-today). Date;

}

Else

{

Return dt. AddDays (-today-7). date;//If today is Sunday, get the date of last Sunday is the date of this week Sunday, so subtract 7 days

}

}

Next week 1st

public static DateTime Getnextmondaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (-today+8). Date;

}

Else

{

Return dt. AddDays (-today+1). date;//If today is Sunday, get the next week 1st period is next Monday date, so subtract 7 days

}

}

Next Sunday Day

public static DateTime Getnextsundaydate ()

{

DateTime Dt=datetime.now;

int today= (int) dt. DayOfWeek;

if (dt. Dayofweek.tostring ()! = "Sunday")//You can also use the today!=0

{

Return dt. AddDays (14-today). Date;

}

Else

{

Return dt. AddDays (7-today). date;//If today is Sunday, get the next Sunday day is next Sunday date, so subtract 7 days

}

}

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.