Given any date, find the first date of the week in C#

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 973
Given a date like "9/23/2016", find the first date of the week. The below code will do so

using System;
using System.Globalization;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var initialDate = Convert.ToDateTime("9/23/2016");

var firstDayOfweek = initialDate.AddDays(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - initialDate.DayOfWeek);

Console.ReadKey();
}

}
}

Comments or Responses

Login to post response