Last Two Weeks End Date - CSharp System

CSharp examples for System:DateTime Week

Description

Last Two Weeks End Date

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from   w w w.  j  av a  2s. com

public class Main{
        public static DateTime LastTwoWeeksEndDate(this DateTime date)
        {
            if (date.DayOfWeek == System.DayOfWeek.Sunday)
                return date.Date.AddDays(-14);
            else
                return date.Date.AddDays(0 - (int)date.DayOfWeek - 7);
        }
        public static int DayOfWeek(this DateTime date)
        {
            if (date.DayOfWeek == System.DayOfWeek.Sunday)
                return 7;
            else
                return (int)date.DayOfWeek + 1;
        }
}

Related Tutorials