-1

In SharePoint 2010

List "Employee", Colum Name "JoinDate" has stored data in (01/31/2014 12.00 PM) mm\dd\yyyy hr:mm PM format.

How to display this data in mm\dd\yyyy only using C# on custom web part?

2

You can try following:

DateTime dt = DateTime.Parse(oListItem["JoinDate"].ToString()
dt.ToString("MM/dd/yyyy");

Safest way to get a date from Sharepoint into a C# datetime field, using object model?

  • I tried above code in console application but its showing date with time however I want to show only time in mm/dd/yyyy format. Thanks. – user3760253 Jun 23 '14 at 6:10
1

Another workaround is create new column and use that column in your code.

  • Create a new calculated column for your list (single line of text)
  • Use the following formula to calculate its value

    =TEXT(Created,"dd mmm yy")

Use the new column to display in your list. http://www.sharepointusecases.com/2009/01/customizing-datetime-format-on-a-list-view-web-part/

or

//Write the code to read your list item
SPListItem item = list.Items[0];
//Get a DateTime object with the list column value
DateTime date = Convert.ToDateTime(item["Date Column Name"]);

String strDate = date.ToString("dd-mmm-yyyy");
//you can also try ("dd/mmm/yyyy")
  • Thanks Waqas Sarwar, Your code work perfectly in my console application. Thanks so much. – user3760253 Jun 23 '14 at 6:11
  • if it solve the issue, please mark the anwser/vote so that community can get benefit from it. – Waqas Sarwar MVP Jun 23 '14 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.