First Day Of Week - CSharp System

CSharp examples for System:DateTime Week

Description

First Day Of Week

Demo Code


using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using System;//  w ww  .  java  2  s .c o m

public class Main{
        public static DateTime FirstDayOfWeek(this DateTime dt)
        {
            var culture = System.Globalization.CultureInfo.CurrentCulture;
            var diff = dt.DayOfWeek - culture.DateTimeFormat.FirstDayOfWeek;
            if (diff < 0)
                diff += 7;
            return dt.AddDays(-diff).Date;
        }
}

Related Tutorials