If I have a value D and want to ensure it is type datetime then is there a difference between the following?
DateTime dtm = Convert.ToDateTi
Convert.ToDateTime
has several overloads that will convert other types to DateTime
. It should be used when you're converting an instance that isn't a DateTime to a DateTime instance. You could also use DateTime.Parse and DateTime.TryParse (if you're trying to parse a string representation).
(DateTime)D
attempts to directly cast an instance to DateTime
. If the instance isn't already a DateTime
prior to the call, an exception will be thrown.