/// /// Calculate this week start date (Date of the week) /// summary> /// Any day in this week param> // / Return to the date of the week, the following specific time, minute, second and incoming value " returns> public static datetime calculatefirstdateofweek (datetime somedate) {Int i = somedate.dayofweek - dayofweek.monday; if (i = = -1) i = 6; // I value> = 0, because enumeration reasons, Sunday is in the forehead, and Sunday-Monday = -1 at this time must 7 = 6. TimeSpan TS = New Timespan (i, 0, 0, 0); return somedate.subtract (TS);}
/// /// Calculate this week end date (Date of Worke Day) /// summary> /// Arbitrary day param> //// Return the date of Worke, after the specific time, division, second and incoming value of returns> public static datetime calculateLastDateOfweek (datetime somedate) {Int i = somedate.dayofweek - dayofweek.sunday; if (i! = 0) i = 7 - i; // Because the enumeration cause, the sunday is ranked at the forefront, and the phase reduction interval is reduced by 7. Timespan TS = New TimeSpan (i, 0, 0, 0); return somedate.add (ts);
/// /// Decisive the date of the selection is this week (which is determined by the current time of the system) /// summary> /// param> /// returns> public static bool IsThisWeek (DateTime someDate) {// get the corresponding someDate Monday DateTime someMon = CalculateFirstDateOfWeek (someDate); // get 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;}}