PDA

Click to See Complete Forum and Search --> : Date Logic


sinha
Sep 20th, 2005, 03:47 PM
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#

jmcilhinney
Sep 20th, 2005, 07:23 PM
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:private DateTime GetFirstDayOfWeek(DateTime date)
{
return date.AddDays(-(int)dt.DayOfWeek);
}If you consider Monday to be the first day of the week then you'll need to do a bit of extra work.

sinha
Sep 21st, 2005, 07:31 AM
Thanks