B
Bob
Because DotNet (inexplicably) can't directly cast SqlDateTime to DateTime
using either CDate or Convert, you have to use ToString first.
I use this function to validate a SQL date:
Public Function IsValidSQLDate(ByVal d As DateTime) As Boolean
Return CDate(SqlDateTime.MinValue.ToString) <= d _
AndAlso CDate(SqlDateTime.MaxValue.ToString) >= d
End Function
On normal, sane machines:
SqlDateTime.MinValue.ToString = '1/1/1753 12:00:00AM'
SqlDateTime.MaxValue.ToString = '12/31/9999 11:59:59PM'.
But on Windows NT machines (even service packed and updated as much as
humanly possible):
SqlDateTime.MinValue.ToString = '1/1/53 12:00:00AM'
SqlDateTime.MaxValue.ToString = '12/31/99 11:59:59PM'
As such, on Windows NT machines the IsValidSQLDate function above fails to
recognize any date not between 1953 and 1999, thereby rendering the values
MS so graciously provides for SqlDateTime.MinValue and SqlDateTime.MaxValue
utterly useless.
Bob
using either CDate or Convert, you have to use ToString first.
I use this function to validate a SQL date:
Public Function IsValidSQLDate(ByVal d As DateTime) As Boolean
Return CDate(SqlDateTime.MinValue.ToString) <= d _
AndAlso CDate(SqlDateTime.MaxValue.ToString) >= d
End Function
On normal, sane machines:
SqlDateTime.MinValue.ToString = '1/1/1753 12:00:00AM'
SqlDateTime.MaxValue.ToString = '12/31/9999 11:59:59PM'.
But on Windows NT machines (even service packed and updated as much as
humanly possible):
SqlDateTime.MinValue.ToString = '1/1/53 12:00:00AM'
SqlDateTime.MaxValue.ToString = '12/31/99 11:59:59PM'
As such, on Windows NT machines the IsValidSQLDate function above fails to
recognize any date not between 1953 and 1999, thereby rendering the values
MS so graciously provides for SqlDateTime.MinValue and SqlDateTime.MaxValue
utterly useless.
Bob