Hi all,
I need to find all weeks of the current year.
currentyear=2009
weeks of 2009 (week 1, 2, 3, 4, 5, 6, 7, 8 ...)
and later to find the corresponding date for the specific week:
week=3;
date of week 3=(18 january - 25 january)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Nov 29, 2009, 4:59 PM
Here I coded solution to solve your problem
Code will Tell you date of Start Date of Week and Also Count total Weeks in Year
if my answer helps you then check "Do you like this answer" check box please :)
protected void Page_Load(object sender, EventArgs e)
{
//Calculate Days in Year
int currentYear = 2009;
int totaldays = Thread.CurrentThread.CurrentCulture.Calendar.GetDaysInYear(2009);
DateTime StartDateOfYear = DateTime.Parse("1/1/"+currentYear);
DateTime endDateOfYear = StartDateOfYear.AddDays(totaldays);
int totalweek=0;
//Add Week Dates in ListBox
for (DateTime d = StartDateOfYear; d <= endDateOfYear; d = d.AddDays(1))
{
//Assume that Week Starts from Sundays
if (d.DayOfWeek == DayOfWeek.Sunday)
{
ListBox1.Items.Add(d.ToShortDateString());
totalweek += 1;
}
}
//Write total Weeks in Year
Response.Write("total weeks in year = " + totalweek);
}