Sticky Wicket: Looping by Month

Some programming problems are difficult to solve. Others are difficult to solve clearly.

Sticky Wicket: Looping by Month

"Sticky wicket."  That's a fun phrase to say, isn't it?

A sticky wicket is a metaphor used to describe a difficult circumstance. It originated as a term for difficult circumstances in the sport of cricket, caused by a damp and soft pitch. Wikipedia

Writing a loop that iterates one month at a time is a subtly tricky problem.  The difficulty isn't so much in writing the code itself.  The challenge is to write the code in such a way that your intent is clear to the reader.

One of my favorite programming quotes is this gem from Martin Fowler:

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

With this in mind, I'll be writing a series of short articles over the next several days exploring several different approaches to looping by month.

If you have a preferred method for solving this sticky wicket, I'd love to hear it.  Let me know @NoLongerSet on Twitter or via email (mike at nolongerset dot com).

UPDATE: Reader submissions (shared with permission):

  • Loop Until using DateAdd

Image by foxycoxy from Pixabay

All original code samples by Mike Wolfe are licensed under CC BY 4.0