I was working on a custom web part that takes the date in Indian format e.g. dd/MM/yyyy while inserting the record in SharePoint custom list. But as we know that SharePoint custom list insert the date value as MM/dd/yyyy format. So it was throwing me the error for invalid string format so below is the code snippet that how i resolved this issue:
string sdate = “15/04/2010”;
DateTime dt = new DateTime();
dt = DateTime.ParseExact(sdate, “dd/MM/yyyy”, new System.Globalization.CultureInfo(“en-US”));
string dateToStore = dt.ToShortDateString();
In this way you are capturing date in dd/MM/yyyy format and storing this date in MM/dd/yyyy format in SharePoint custom list.
Happy Coding 🙂