Get First Day Of Week - CSharp System

CSharp examples for System:DateTime Week

Description

Get First Day Of Week

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w  w w  . j  av  a2s . c  o m

public class Main{
        public static DateTime GetFirstDayOfWeek(DateTime now, int WeekNum = 0)
        {
            int rs = 1;
            switch (now.DayOfWeek)
            {
                case DayOfWeek.Monday: 
                    rs = 1;
                    break;
                case DayOfWeek.Tuesday:
                    rs = 2;
                    break;
                case DayOfWeek.Wednesday:
                    rs = 3;
                    break;
                case DayOfWeek.Thursday:
                    rs = 4;
                    break;
                case DayOfWeek.Friday:
                    rs = 5;
                    break;
                case DayOfWeek.Saturday:
                    rs = 6;
                    break;
                case DayOfWeek.Sunday:
                    rs = 7;
                    break;
            }
            return now.AddDays((1 - rs)).AddDays(7 * WeekNum);
        }
}

Related Tutorials