Tuesday, 29 September 2009

DateTime.Min != SqlDateTime.Min

Yes, as the title says, .Net DateTime Minimum does not equal Sql Servers equivalent. For whatever reason you come across this gem of an issue you have a couple of options to get around it.

1. Use a .net Nullable datetime instead. i.e. Declare your "DateTime" as "DateTime?". Putting question marks after a lot of .Net variable types in C# turns them into nullable types.

2. If you really do need the min date, use SqlDateTime.Min.Value. "Value" gives you access to a DateTime type containing SQLs min date.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.