About Me

My photo
Northglenn, Colorado, United States
I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).

Thursday, August 31, 2006

Interesting Read: The Problem with Threads


http://www.computer.org/portal/site/computer/
menuitem.5d61c1d591162e4b0ef1bd108bcd45f3/index.jsp?&pName=computer_level1_article&TheCat=1005&
path=computer/homepage/0506
&file=cover.xml&xsl=article.xsl

Set Day of the Month

Ok, had to quickly write this one, to find the nth day of a month.

private System.DateTime SetDayOfMonth(System.Int32 nth, System.DayOfWeek weekday, System.Int32 month, System.Int32 year)
{
System.DateTime dath = new DateTime(year, month, 1); //set to first day of the month
//get to the first weekday looking for
while(dath.DayOfWeek != weekday)
{
dath = dath.AddDays(1);
}

if(nth > 1)
{
dath = dath.AddDays((nth - 1) * 7);
}
else
{
dath = dath.AddMonths(1);
dath = dath.Substract(TimeSpan.FromDays(1); //last day of the month
while(dath.DayOfWeek != weekday)
{
dath = dath.Subtract(TimeSpan.FromDays(1)); //cycle backwards to last
}
dath = dath.Subtract(TimeSpan.FromDays(((nth * -1) - 1) * 7));
}
return dath;
}