String was not recognized as a valid DateTime

I got this error when I was trying to convert date string with format dd/MM/yyyy.
Solution:
First Import below Namespace
using System.Globalization;
Replace STRDATE with your date. And use any of the below code for conversion.
Datetime DT = DateTime.ParseExact(STRDATE,"dd/MM/yyyy",System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)
OR
DateTime date = DateTime.ParseExact(STRDATE, "dd/MM/yyyy", CultureInfo.InvariantCulture);
OR
DateTime date = DateTime.ParseExact(STRDATE, "dd/MM/yyyy", null);

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More