Click here to Skip to main content
15,889,838 members
Articles / Programming Languages / Visual Basic
Alternative
Tip/Trick

First day date in week based on particular date

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
29 Nov 2010CPOL 5.9K   1  
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)


Written By
Software Developer (Senior)
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --