views:

321

answers:

2

Hi all,

I want to initialize a DateTime entity to the minimum possible date in TSQL.
(as you all know its 1/1/1753)

Is there a standard way to represent this date in ASP.NET ?
I mean doing something like DateTime.SQLMinValue (this doesn't exist), instead of doing
new DateTime(year, month, date) ?

If so, please post it, Thanks!

+1  A: 

EDIT: Luke is right, extension methods are not an appropriate solution to this problem.

Nebakanezer
The fact that you can only call extensions on instances of a type rather than the type itself could lead to some *very* unintuitive code: `var confusing = new DateTime(2009, 12, 07).SQLMinValue();` etc.
LukeH
Very good point Luke. This is not the appropriate use of extension methods. Thanks for pointing this out.
Nebakanezer
Thanks Luke, I didn't know that, useful point :)
Mahesh Velaga
+6  A: 
System.Data.SqlTypes.SqlDateTime.MinValue;

...and the MSDN documentation for reference.

Justin Niessner
If I have to compare it with some DateTime value, is it fine if I do DateTime.Now != (DateTime) SqlDateTime.MinValue or is there a better way to do that? Thanks for the answer :)
Mahesh Velaga
I can't remember if you can directly cast from SqlDateTime to DateTime. If not, then you could do DateTime.Now != new DateTime.Parse(SqlDateTime.MinValue.ToString());
Justin Niessner