SmartDate versus Nullable<DateTime>

SmartDate versus Nullable<DateTime>

Old forum URL: forums.lhotka.net/forums/t/9067.aspx


jh72i posted on Friday, June 11, 2010

Folks,
Just a quick question about whether or not we can replace SmartDate with Nullable<DateTime>?

Thanks

CBoland replied on Friday, June 11, 2010

Throwing my $0.02 in...

Given nullable DateTime, SmartDate seems like an anachronism held over for backward compatibility. My current project uses them, but on my next project I'm going to try using nullable DateTime instead.

RockfordLhotka replied on Friday, June 11, 2010

SmartDate does two things:

  1. It understands the concept of an empty date
  2. It does powerful string parsing/conversion

Basically, if you want to bind a textbox control to a date property, how do you do it? Especially if an empty text value means an empty date. And consider than an empty date might be the smallest possible, or largest possible date value in terms of comparisons with other date values.

SmartDate is intended to solve that specific problem.

It is true that some UI technologies now include date/time pickers that are powerful enough to represent this concept with a nullable date. But that's not universally true. And even in that case, a nullable date can't be compared to a real date in the way SmartDate can.

A great example is a ShipDate property. If it is empty, that means the order will ship infinitely far in the future, so that empty date is larger than any other date. In other cases an empty date might need to be the smallest possible date.

So I don't think SmartDate is without value. You just need to understand the value it provides, and use it when you need the functionality it offers.

 

jh72i replied on Thursday, July 22, 2010

Thanks for these replies folks.

Copyright (c) Marimer LLC