find week ending date of last completed week

后端 未结 5 962
独厮守ぢ
独厮守ぢ 2021-01-04 07:04

For any given date, how would you find the week ending date of the last completed week, if your week runs from Sunday to Saturday?

5条回答
  •  醉酒成梦
    2021-01-04 07:57

    .NET DateTimes expose a DayOfWeek property. You can leverage that in this case:

    var currDay = DateTime.Today.DayOfWeek;
    //currday is now an enumeration with Sunday=0, Saturday=6
    //We can cast that to a number and subtract to get to the previous Saturday
    var EndOfLastWeek = DateTime.Today.AddDays(((int)currDay+1)*-1);
    

提交回复
热议问题