How to convert sqldatetime.minvalue to datetime?
I can't seem to convert a sqldatatime.minvalue to a datetime object.
I tried:
Datetime dt = Convert.ToDateTime(SqlDateTime.MinValue);
That obviously didn't work.
No need to convert. SqlDateTime
has a Value property that returns a DateTime
.
DateTime dt = SqlDateTime.MinValue.Value;
Any reason not to just use the explicit conversion operator?
DateTime dt = (DateTime) SqlDateTime.MinValue;
That works for me:
using System;
using System.Data.SqlTypes;
class Test
{
static void Main()
{
DateTime dt = (DateTime) SqlDateTime.MinValue;
Console.WriteLine(dt);
}
}