Pages

Subscribe:

Ads 468x60px

Sunday, May 29, 2011

how to find the dates on sundays in a specific month using asp.net with c#

First of all add the following NameSpace in your .aspx.cs File
using System.Globalization; 
protected void Page_Load(object sender, EventArgs e) 

DateTime currentDateTime=System.DateTime.Now; 
int year=currentDateTime.Year; 
int months=currentDateTime.Month; 
GetDatesOfSundays(year, months, DayOfWeek.Sunday); 

protected void GetDatesOfSundays(int year, int month, DayOfWeek dayName) 

CultureInfo ci = new CultureInfo("en-US"); 
for (int i = 1; i <= ci.Calendar.GetDaysInMonth(year, month); i++) 

if (new DateTime(year, month, i).DayOfWeek == dayName) 
Response.Write(i.ToString() + ","); 

No comments:

Post a Comment