Empty SmartDate .ToString problem

Empty SmartDate .ToString problem

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


Massong posted on Wednesday, June 07, 2006

Hi all,

I’ve a small problem with the SmartDate structure in CSLA 2.0. I read an empty SmartDate from a SQL Server 2000 database and even though emptyIsMin is set to false and the date value is “#12/31/9999 11:59:59 PM#” the DateToString function doesn’t return an empty string.

The debugger shows that value is “#12/31/9999 11:59:59 PM#” and that Date.MaxValue is “#12/31/9999 11:59:59 PM#”, but value = Date.MaxValue returns false.

So I checked the ticks and they are different: value: 3155378975999970000 and Date.MaxValue: 3155378975999999999.

How can this be? Does anybody else have this problem?

Thanks,
Christian

ajj3085 replied on Wednesday, June 07, 2006

FWIW, the MinValue for DateTime shouldn't have 9999 as the year.

At any rate, yes, this is a problem in that the Sql DateTime column doesn't have the persision of the .Net DateTime.  So in your tests, you'll probably have to round out the least significate portion of the .Net DateTime.

However you're talking about DB data.  If you want to store an empty date in the database, store a null.  When you load a null you then create an empty SmartDate for the business object's property value.

HTH
Andy

Massong replied on Wednesday, June 07, 2006

Hi Andy,

 

thank you for your reply. We don’t use empty minimum dates in our projects – only empty maximum dates. So I have never noticed that I have used myDate.Date to store the date into the database instead of myDate.DBValue. While Date.MaxValue is a valid SQL Date that causes no errors – Date.MinValue is an invalid SQL Date that would have caused errors. Thank you for your hint to the precision of the SQL DateTime.

 

Thanks,
Christian

Copyright (c) Marimer LLC