I have used a textbox to store a date in DD-MM-YYYY format and since i use SQL server i used to get the value from the textbox and then place it in a variable of type DateTime dt
DateTime dt = DateTime.ParseExact(TextBox10.Text,"MM-DD-YYYY",CultureInfo.InvariantCulture);
I am getting format specification error, I went through many documentation but still couldn’t get where i am going wrong
This i am using C# and ADO.net
Please can anyone correct me?
It looks like you mixed up DD and MM. Try below:
Notice that I changed “DD” to “dd”!
UPDATE:
Ok, so I changed “YYYY” to “yyyy” and ran the code below and it parsed sucessfully:
If your users really are passing in dates in the format “dd-MM-yyyy” this should work for you. Keep in mind that the second string has nothing to do with whatever format you are storing in your database. It only has to do with the format of the first string argument in ParseExact. HTH.