Search Results:

Saturday, July 16, 2016

Simple Code to get First Day of Week and Last Day of Week

I wanted a simple and quick way to get the start of week and end of week to do some data processing for the week. Here is a simple three line code that can help achieve this.

        DateTime dt  = DateTime.Now();
        DateTime FirstDayofWeek = dt.AddDays(-(int)dt.DayOfWeek);
        DateTime LastDayofWeek = FirstDayofWeek.AddDays(6);

Hope it helps, Thanks!!!

No comments:

Post a Comment