Last Day Of Week - CSharp System

CSharp examples for System:DateTime Week

Description

Last Day Of Week

Demo Code


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

public class Main{
        public static DateTime LastDayOfWeek(this DateTime dt)
        {
            return dt.FirstDayOfWeek().AddDays(6);
        }
        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