Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

First day date in week based on particular date

5.00/5 (1 vote)
29 Nov 2010CPOL 6K  
public static DateTime GetFirstDayOfWeek(this DateTime date) { var dfi = DateTimeFormatInfo.CurrentInfo; var firstDayOfWeek = date; while (firstDayOfWeek.DayOfWeek != dfi.FirstDayOfWeek) firstDayOfWeek=...
C#
public static DateTime GetFirstDayOfWeek(this DateTime date)
        {
            var dfi = DateTimeFormatInfo.CurrentInfo;
            var firstDayOfWeek = date;
            while (firstDayOfWeek.DayOfWeek != dfi.FirstDayOfWeek)
                firstDayOfWeek= firstDayOfWeek.AddDays(-1);
            return firstDayOfWeek;
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)