Convert date from dd/MM/yyyy to MM/dd/yyyy for storing in SharePoint list or Sql Server Database


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 šŸ™‚

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s