Date Info

Ever needed to know if today's date is the 2nd Monday of January? Or if its a holiday? Or maybe you just want to know if February 7th, 2009 is in the first week of the month?

If you currently do this today, then you might have a config file full of dates that you care about, or perhaps a database table full of rows that you can key off of.  With both of these approaches you will need to update the list each year to take into account that the holiday that you care about just might fall on a different date. This becomes a pain to maintain and makes it easy to forget to update, causing potential for errors because the dates are off.

I have run into this a few times when working on ecom websites that wanted to disable the "one day shipping" options on holidays and other custom dates. So in having to deal with this issue once again, I decided that I would write some code that would determine if the given date matches the one in my list.

Types of Dates I want to support:

  • Holidays and dates that are static, ie: July 4th 2009.  No matter the year they always fall on the same date.
  • Holidays and dates that are dynamic, ie: 2nd Sunday in May (Mothers day).  The date of this one changes every year.

Given a date I want to know the Following:

  • Day of the week (Yes, I know DateTime supports this already)
  • Week of the month*
  • If its a weekday
  • If its a weekend
  • Day of the year
  • If it matches a given date (This can be one of the two date types above, static or dynamic)

Support of Custom dates:
The library support matching a given date to one that has been pre-configured.  It allows you to set up those custom dates in one of two ways:

  • A config file (see example in source code)
  • In code (this can be part of your boot strap code... ie: in global.asx)

So check out this library and its examples; see if it helps you like it does me.  I'm not handing out the source code just yet but I might after another version or two.  I still have a handful of features that I will want to add if people are into using it.  If you like it (or not) email me, I would love to get some feedback on it!

 

Download:
    Coming soon! [2009.01.10]

 

* This is not as easy to determine as one might think. so its based on the days of the week; Sunday being the first day of the week and Saturday being the last.  So you might span the first two weeks of a month in the first seven days.  This also means that might have more than 4/5 weeks.

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen