none
Change date format of created column of list to display in web part

    Question

  • Hi,

     

    I want to display date in format "dd-mmmm-yy" of "Created" column of particular list in web part.

    can we use datetime? how it can be use?

    Please help me out.

    Thanks in advance.

    Regards,

    Jayashri

    Thursday, March 22, 2012 3:13 AM

Answers

  • Try the below code

    //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")


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010

    • Marked as answer by Jayashri10 Thursday, March 22, 2012 7:05 AM
    Thursday, March 22, 2012 5:12 AM

All replies

  • Hello Jayashri,

    You can display the date in that format...In what type of webpart are you trying to display this? I mean (Custom webpart or OOB webpart like CQWP)


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010

    Thursday, March 22, 2012 3:28 AM
  • Hi Ram,

    Thanks for your response.

    In custom web part, i want to show.

    Can you please tell me how to get that result?

    Thanks in advance.

    Regards,

    Jayashri

    Thursday, March 22, 2012 5:05 AM
  • Try the below code

    //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")


    Ram Prasad Meenavalli | MCTS SharePoint 2010 | MCPD SharePoint 2010

    • Marked as answer by Jayashri10 Thursday, March 22, 2012 7:05 AM
    Thursday, March 22, 2012 5:12 AM
  • Hi Ram,

    Thanks for your help.

    Just one thing: date format should be ("dd-MMMM-yyyy") for require output as 21-March-2012.

    Anyways you helped me a lot

    Thanks.

    Regards,

    Jayashri

    Thursday, March 22, 2012 7:04 AM