Any difference between DateTime.Parse and Convert.ToDateTime?
DateTime.Parse
has an overload that takes only one String
and nothing else and it uses the current Locale
info without you having to pass it in.
DateTime.Parse
will throw an Exception
when a null string is passed, Convert.ToDateTime
will return DateTime.MinValue
on passing a null value.
Per an answer on another forum from Jon Skeet...
Convert.ToDateTime uses DateTime.Parse internally, with the current culture - unless you pass it null, in which case it returns DateTime.MinValue.
If you're not sure string is a valid DateTime
, use neither and instead, use DateTime.TryParse()
If you're sure the string is a valid DateTime
, and you know the format, you could also consider the DateTime.ParseExact()
or DateTime.TryParseExact()
methods.