Display Weekly Times of the week:
// <Summary>
/// Returns a 3-character string array.
/// </Summary>
/// <Returns> getweekday [0] = weekly; getweekday [1] = the first day of the week; getweekday [2] = the last day of the week </returns>
Public String [] getweekday ()
{
String [] Inti = new string [3];
Datetime day = datetime. parse (datetime. Today. Year + "-1-1 ");
System. dayofweek datetime = day. dayofweek;
Int daycount = datetime. Today. dayofyear;
Int I = (daycount + AA (datetime)-2)/7 + 1;
INTI [0] = I. tostring ();
INTI [1] = day. adddays (daycount-1). tostring ("mm DD, YYYY ");
INTI [2] = day. adddays (daycount + 5). tostring ("mm DD, YYYY ");
Response. Write ("day" + I + "Week ");
Return Inti;
}
Private int AA (system. dayofweek weekday)
{
Switch (weekday. tostring ())
{
Case "Sunday ":
Return 1;
Case "Monday ":
Return 2;
Case "Tuesday ":
Return 3;
Case "Wednesday ":
Return 4;
Case "Thursday ":
Return 5;
Case "Friday ":
Return 6;
Case "Saturday ":
Return 0;
Default:
Return 8;
}
}
///////////////////////////////////// /// // C # display the favorites of the week
> ///
// calculate the start date of the week (the date of the week)
///
/// any day of the week
// returns the day of the week, the following time, minute, and second values are equal to the input values
Public static datetime calculatefirstdateofweek (datetime somedate)
{< br> int I = somedate. dayofweek-dayofweek. monday;
if (I =-1) I = 6; // I value> = 0. Due to enumeration, Sunday is at the top. At this time, Sunday-Monday =-1 must be + 7 = 6.
timespan Ts = new timespan (I, 0, 0, 0);
return somedate. Subtract (TS);
}
///
// calculate the end date of the week (the day of the week)
///
/// any day of the week
// returns the Sunday date, the following time, minute, and second values are equal to the input values
Public static datetime calculatelastdateofweek (datetime somedate)
{< br> int I = somedate. dayofweek-dayofweek. sunday;
if (I! = 0) I = 7-I; // due to enumeration, Sunday is at the top of the list, and the subtraction interval is reduced by 7.
timespan Ts = new timespan (I, 0, 0, 0);
return somedate. Add (TS);
}
/// <Summary>
/// Determine whether the selected date is this week (this week is determined by the system's current time)
/// </Summary>
/// <Param name = "somedate"> </param>
/// <Returns> </returns>
Public static bool isthisweek (datetime somedate)
{
// Obtain Monday corresponding to somedate
Datetime somemon = calculatefirstdateofweek (somedate );
// Get this Monday
Datetime nowmon = calculatefirstdateofweek (datetime. Now );
Timespan Ts = somemon-nowmon;
If (TS. Days <0)
TS =-ts; // positive
If (TS. days> = 7)
{
Return false;
}
Else
{
Return true;
}
}
Obtain the start and end dates of the week from the current date.
11:58:15| Category:SQL| Tag:Datetime string yyyy tostring convert |Font SizeLargeMediumSmall Subscription
/// <Summary>
/// Start time and end time of the week
/// </Summary>
/// <Param name = "DT"> </param>
/// <Returns> </returns>
Private string weekrange (system. datetime DT)
{
Int weeknow = convert. toint32 (Dt. dayofweek );
Int daydiff = (-1) * weeknow + 1;
Int dayadd = 7-weeknow;
String datebegin = system. datetime. Now. adddays (daydiff). tostring ("yyyy-mm-dd ");
String dateend = system. datetime. Now. adddays (dayadd). tostring ("yyyy-mm-dd ");
Return datebegin + "/" + dateend;
}
// start and end time of the month
private string months ()
{< br> string moth = convert. todatetime (datetime. now ). tostring ("yyyy-mm-") + "01";
string mothday = convert. todatetime (datetime. now ). tostring ("yyyy-mm-dd");
return moth + "/" + mothday;
}
// start time of the current year
private string years ()
{< br> string year = convert. todatetime (datetime. now ). tostring ("YYYY") + "-01-01";
string yearday = convert. todatetime (datetime. now ). tostring ("yyyy-mm-dd");
return year + "/" + yearday;
}