Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Needed Please help Me

Status
Not open for further replies.

Ahssan

Programmer
Nov 4, 2003
27
KW
Dear All,

I will highly appreciate if some body help me out with this small but confusing for me problem.

I have a dropdown 1 which has all months in it
I have drop down 2 which has all weeks in it

When user selects month and a week from drop downs i want the application to return all the dates which are coming with in that week of the selected month.

Like


January ----- 1st Week

should give me dates from 01/01/2004 till the end of the that week. This functionality i only want for current running year. Thankyou all in advance for helping me out.

Regards,

Ahsan
 
I haven't put this in Visual Studio to make sure it compiles, but try this:
Code:
// selMonth is the year the user chose
// selWeek is the week within selMonth

using System.Globalization;

// Find the week in the month for the current year
Calendar cal = CultureInfo.InvariantCulture.Calendar;
DateTime dt1 = new DateTime.Now;
DateTime dt2 = new DateTime(dt1.Year, selMonth, 1);
DateTime dt3 = cal.AddWeeks(dt2, selWeek);

// back up to first day of the week.  Note that different
// cultures have different starts of the week.
while (dt3.DayOfWeek <> CultureInfo.InvariantCulture.DateTimeFormat.FirstDayOfWeek)
{
   dt3.AddDays(-1);
}

// Go forward by a week's worth.  We're assuming 7 days in the week.
for (int i = 0; i < 7; i++)
{
   System.Console.WriteLine(dt3.ToString());
}
Chip H.



____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top