I'm trying to parse a String into a DateTime object but it seems to always default the month to 1. So let's say I give it a string 30/05/1970 it ends up being converted to DateTime object with the month value equal to 1.
Here's the code:
public static DateTime ToDateTime(this String value, String format)
{
Contract.Requires(!String.IsNullOrEmpty(value));
Contract.Requires(!String.IsNullOrEmpty(format));
DateTime date;
if (DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
return date;
}
throw new ArgumentException("Input value is not a valid date.");
}
Note that the format that is being passed to the method is dd/mm/yyyy.
Any thoughts?