Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to get first and last dates of week by providing one date. This date may be of any day of the week. Is there any way to get the last and first days of particular that week? X|

Have you considered reading the documentation for the DateTime class, or even using intellisense to look at the methods it offers ?
jisha Johnson 5-Jul-10 6:28am
I've got the methods like getting day of week and all. Bt I want to get that particular week's first day and last day? I cant get anything like that. I've searched many places. Bt I haven't got an answer. If u can give me any link to the doc.
Christian Graus 5-Jul-10 6:37am
Notwithstanding that Abhishek points out an issue that did not occur to me ( knowing if the first day is considered Mon or Sun ), getting the first day of the week, is basic maths. If you're on day 4, the first day, is four days ago ( because I believe it's 0 indexed ).
You can get the day of the week using this link.
Based on this date and day, you should easily be able to get the first and last dates of the week by writing some of your own code logic.
jisha Johnson 5-Jul-10 7:42am
Thank u.This was informative
I think this is what you wanted for :

public DateTime GetFirstDate(DateTime thisDate)
          CultureInfo cinfo = Thread.CurrentThread.CurrentCulture;
          DayOfWeek currentfdayname = cinfo.DateTimeFormat.FirstDayOfWeek;
          DayOfWeek currenttdayname = cinfo.Calendar.GetDayOfWeek(DateTime.Now);

          int diff = currenttdayname - currentfdayname;
          DateTime firstDate = thisDate.AddDays(-diff);

          return firstDate;

I hope this would help you.:rose:
jisha Johnson 5-Jul-10 7:41am
With some changes this was my answer. Thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900