// Determine the date based on the number of weeks
Private datetime getweekofdate (INT year, int I)
{
// Int month = 1;
Datetime yeard = new datetime (year, 1, 1 );
Int week = convert. toint32 (yeard. dayofweek );
If (week = 0)
{
Week = 7;
}
Int outday = I * 7-(week-1); // throw the excess days to the day of the week
Int sum = outday; // the number of days that have elapsed in the week. Sunday is the last day.
Int day = 6; // fixed borrow
Try
{
If (sum <7) // week 1
{
Yeard = new datetime (year-1, 12, 31-(day-sum ));
}
Else
{
For (INT x = 1; x <13; X ++)
{
Int nextmonth = system. datetime. daysinmonth (year, x + 1); // The next month
Int daysinjuly = system. datetime. daysinmonth (year, x); // number of days in the current month
If (Sum-daysinjuly) <0)
{
If (sum <= 6)
{
Int lastmonth = system. datetime. daysinmonth (year, X-1); // previous month
Yeard = new datetime (year, X-1, lastmonth-(day-sum ));
}
Else
If (sum <daysinjuly)
{
Yeard = new datetime (year, X, Sum-day );
}
Break;
}
Else
If (Sum-daysinjuly) <0 & (Sum-daysinjuly-nextmonth) <Day)
{
Day = sum-daysinjuly;
Yeard = new datetime (year, X, daysinjuly-day );
Break;
}
Sum = sum-daysinjuly;
}
}
}
Catch (exception ex) {MessageBox. Show ("data error! ");}
Return yeard;
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/fulminati/archive/2009/03/13/3987422.aspx