I have a datetime property similar to the following:
private DateTime birthDate; public DateTime BirthDate { get { return birthDate; } set { birthDate = value; } }
For displaypurposes, I use a datetime picker with "dd-MM-yyyy" format. However, to actually set the property, I want to use "yyyy-MM-dd" format. I am trying the following code but I keep receiving "String was not recognized as a valid DateTime":
BirthDate = DateTime.ParseExact (txtDateOfBirth.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture);
The reason I want to use yyyy-MM-dd format for setting the property is that the property value will be saved in SQL Server whichs accepts (yyyy-MM-dd) format irrespective of culture used.