CSharp · Console
using System;
using System.Globalization;
public class Program
{
public static void Main()
{
DateTime date = DateTime.Now; //get current datetime
//get year from the date
int year = date.Date.Year;
//set the first day of the year
DateTime firstDay = new DateTime(year, 1, 1);
//get Day of the week
DayOfWeek day = date.DayOfWeek;
CultureInfo cul = CultureInfo.CurrentCulture;
//get no of week for the date
int weekNo = cul.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
//get no of day
int days = (weekNo - 1) * 7;
DateTime dt1 = firstDay.AddDays(days);
DayOfWeek dow = dt1.DayOfWeek;
DateTime startDateOfWeek = dt1.AddDays(-(int)dow);
DateTime endDateOfWeek = startDateOfWeek.AddDays(6);
Console.WriteLine("Start Of Week: " + startDateOfWeek.ToShortDateString());
Console.WriteLine("End of week:" + endDateOfWeek.ToShortDateString());
}
}