I want to convert a string to DateTime, but I get the following error.
String was not recognized as a valid DateTime.
int firstDayOfMonth = 1; int lastDayOfMonth = 31; int month = 3; int year = 2006; string sStartDate = string.Format("{0}/{1}/{2}", firstDayOfMonth, month, year); string eEndDate = string.Format("{0}/{1}/{2}", lastDayOfMonth, month, year); //This one works DateTime sDate = Convert.ToDateTime(startDate, CultureInfo.CurrentCulture.DateTimeFormat); //This one doesnt work DateTime eDate = Convert.ToDateTime(eEndDate, CultureInfo.CurrentCulture.DateTimeFormat); Then I tried this
DateTime date = new DateTime(year, month, lastDayOfYear); But then it gives me 3/1/2006 but I need it in dd/MM/yyyy
What can I do to convert the string to dd/MMyyyy?
en-USbut you are expecting it to been-GB. Check your control panel settings.CurrentCulture?