but it threw exception to me
Problem:
Your date contains /
seperator ("28/08/2012"
) and you are not giving that in your date string format ("ddMMyyyy"
).
Solution:
It should be "dd/MM/yyyy"
.
This way
DateTime.ParseExact("28/08/2012", "dd/MM/yyyy", CultureInfo.InvariantCulture)
.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
After doing that we will receive a DateTime object with your populated dates which is transferred to string using .ToString()
with desired date format "MM/dd/yyyy"
and optional culture info CultureInfo.InvariantCulture
.