Click here to Skip to main content
15,610,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

Please help me I am unable to find on net. I need to find date of particular day in a week, which means user click on Sunday then date of Sunday should display on label.

thanks in advance
Updated 1-Feb-11 22:55pm
shakil0304003 2-Feb-11 5:32am    
what you tried?

Did you think of this logically? A month can have 4/5 same days (for e.g. lets say sunday); how would you know that user wanted the 1st sunday or the last sunday of the month.

For sure, you need to consider more parameters like week number etc.

With the likely code:

private DateTime GetDateBasedOnDay(string Pstrday)
			DateTime LobjDate = null;

			DateTime LobjToday = DateTime.Now.Date;
			DayOfWeek LobjDayToday = LobjToday.DayOfWeek;

			DayOfWeek LobjLookUpDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), Pstrday);

			while (LobjToday.DayOfWeek != LobjLookUpDay)
				LobjToday = LobjToday.AddDays(1);

			LobjDate = LobjToday.Date;

			return LobjDate;
Share this answer
bburhanbohra 2-Feb-11 5:13am    
i just want date of next day... if user select sunday and today is monday then it show sunday's date...
Manas Bhardwaj 2-Feb-11 5:32am    
Updated my answer
Manas Bhardwaj 2-Feb-11 5:37am    
Update my answer. This might help you.
JF2015 2-Feb-11 5:34am    
Looks as a simple enough solution for the OP to understand it. 5+
Manas Bhardwaj 2-Feb-11 5:39am    
thnks :)
You can use it.
DayOfWeek week1 = DayOfWeek.Tuesday;
int dif = week1 - DateTime.Now.DayOfWeek;
if (dif < 0)
    dif += 7;

DateTime dt = DateTime.Now.AddDays(dif);
Share this answer
bburhanbohra 2-Feb-11 6:25am    
shakil0304003 2-Feb-11 6:46am    

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