I need to make a function, where, when I provide a Date as a parameter, it should return the first day of the week (the date falls.). Pls help me with the logic. I am coding in c#
Printable View
I need to make a function, where, when I provide a Date as a parameter, it should return the first day of the week (the date falls.). Pls help me with the logic. I am coding in c#
It depends what day you consider to be the first of the week. The DayOfWeek enumeration considers Sunday to be day 0 and Saturday to be day 6. If that is OK with you then you can use this:If you consider Monday to be the first day of the week then you'll need to do a bit of extra work.Code:private DateTime GetFirstDayOfWeek(DateTime date)
{
return date.AddDays(-(int)dt.DayOfWeek);
}
Thanks