I recently needed to make a change to some code that had a routine for getting the week currently in. I needed to add the ability to get the previous / last week relative to this week. No problem, I would just work off of the existing routine.

It took me a little bit of time to digest the routine and realized I needed to simplify the routine and even though the code is in VB I wanted to remove the dependence on the Microsoft.VisualBasic library as well. This means getting rid of Weekday, DateAdd, etc and replace with the framework standard. I love not reinventing the wheel and happened to find a nice pointer on stack overflow.

11 lines of code and three variables down to three lines and one variable with the added benefit of being easier to read, understand and the reliance on Microsoft.VisualBasic gone (at least for this code). Since I needed to create another routine that returns last week I decided as suggested in one of the stack overflow answers to create an extension on the date type.