DotNetLib.DateTimeExtensions

Variety of helper methods and extensions to assist when dealing with dates.

IsWeekendDay and IsWeekday (extensions)

Checks an array of any type to see if it is null or has zero length
DateTime date = new DateTime(2009, 1, 1); // this is a Thursday
bool isWeekend = date.IsWeekendDay();
bool isWeekday = date.IsWeekday();
// isWeekend will be false here
// isWeekday will be true here

date = date.AddDays(2); // make it Saturday
isWeekend = date.IsWeekendDay();
isWeekday = date.IsWeekday();
// isWeekend will be true here
// isWeekday will be false here
Home

NextWeekendDay and NextWeekday (extensions)

Advances a DateTime to a future date.
DateTime date = new DateTime(2009, 1, 1); // this is a Thursday
DateTime nextDay = date.NextWeekendDay(); // this will now be Saturday the 3rd
nextDay = nextDay.NextWeekday(); // this will now be the Monday the 5th
Home

Last edited Oct 9, 2010 at 5:56 AM by joshucar, version 2

Comments

No comments yet.