Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

C#: Montag eines aktuellen Wochentages berechnen

19.01.2019 (👁1753)


 

Wie ermittelt man den Montag aus einem aktuellen Datum?

Ich möchte wissen, welcher Tag der Montag ist, wenn ich einen aktuellen Tag in C# eingebe.

 

Lösung über dt.DayOfWeek.

Dabei ist 0=Sonntag und 1=Montag

 

private DateTime Get_Monday_of_Date(DateTime dt)

{

    //------------< Get_Monday_of_Date() >------------

    //*gets the monday of a day

    //*dt.DayOfWeek -> 0=Sunday, 1=Monday..

    int intDayOfWeek = (int)dt.DayOfWeek;

    int intOffset_Weekday = intDayOfWeek == 0 ? -6 : intDayOfWeek - 1;   //*condition ? result : alternative

 

    DateTime dtMonday = dt.AddDays(intOffset_Weekday);

 

    //< out >

    return dtMonday;

    //</ out >

    //------------</ Get_Monday_of_Date() >------------

}