Saturday, January 05, 2008

Create a Date only property (C# example)

One of the minor frustrations in the .Net framework is that there is a datetime type but note a date-only type. There are many times when I want to represent a date but carrying along a time value seems extraneous and sometimes can cause issues in comparisons, etc.

One simple solution (I'm sure there are others and I'd love to hear how you handle it) is to create date-only properties in your objects. It is simple enough to do, a C# example follows:

private DateTime _Date01;
public DateTime Date01

get { return _Date01.Date; }
set { _Date01 = value.Date; }

Hope that helps.

Joe Kunk
Okemos,MI USA