none
Format SharePointWebControls:DateTimeField with longDate RRS feed

  • Question

  • Hi ,

    I have a datetime field with date and time activate.  

    In my code I have :

    <SharePointWebControls:DateTimeField FieldName="4aaf3b75-d54b-4198-b100-bd3aee42224a" runat="server" />

    I want customize the date with "longDate" or "shortDate" format. Please suggest how to proceed. 

    I have a datetime field with date and time activate.  

    In my code I have :

    <SharePointWebControls:DateTimeField FieldName="4aaf3b75-d54b-4198-b100-bd3aee42224a" runat="server" />

    I have a datetime field with date and time activate.  

    In my code I have :

    <SharePointWebControls:DateTimeField FieldName="4aaf3b75-d54b-4198-b100-bd3aee42224a" runat="server" />


    Mohor

    Monday, July 11, 2016 10:30 AM

Answers

  • Hello. The DateTimeField control is probably uncustomizable (see

    http://sharepoint.stackexchange.com/questions/84318/how-to-display-date-in-page-layout-in-specific-format

    http://sharepoint.stackexchange.com/questions/67206/sharepointwebcontrolsdatetimefield-show-both-date-and-time-for-input

    https://bilalasmar.wordpress.com/2012/07/16/render-custom-date-format-for-datetime-field-in-page-layouts/

    ).

    I suggest using field client side rendering  for that or use another control to display value (maybe inline code as one of the articles above suggests).


    If my suggestion helped you to solve your problem, please don't forget to mark it as Answer

    Monday, July 11, 2016 10:59 AM
  • Hi,

    SharePoint DateTime field control not provide easy way to set the datetime format.

    We can use the inline code below to customize the datetime format:

    <%=SPContext.Current.ListItem["Created"] != null? (new DateTime(SPContext.Current.ListItem["Created"].ToString()).ToString("USE FORMAT DATE STRING HERE"): string.Empty %>

    More information:

    DateTime.ToString Method (String)

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, July 12, 2016 9:48 AM

All replies

  • Hello. The DateTimeField control is probably uncustomizable (see

    http://sharepoint.stackexchange.com/questions/84318/how-to-display-date-in-page-layout-in-specific-format

    http://sharepoint.stackexchange.com/questions/67206/sharepointwebcontrolsdatetimefield-show-both-date-and-time-for-input

    https://bilalasmar.wordpress.com/2012/07/16/render-custom-date-format-for-datetime-field-in-page-layouts/

    ).

    I suggest using field client side rendering  for that or use another control to display value (maybe inline code as one of the articles above suggests).


    If my suggestion helped you to solve your problem, please don't forget to mark it as Answer

    Monday, July 11, 2016 10:59 AM
  • You can build your own sharePoint Delegate control and use that Delegate control in your page
    Monday, July 11, 2016 1:21 PM
  • Hi,

    SharePoint DateTime field control not provide easy way to set the datetime format.

    We can use the inline code below to customize the datetime format:

    <%=SPContext.Current.ListItem["Created"] != null? (new DateTime(SPContext.Current.ListItem["Created"].ToString()).ToString("USE FORMAT DATE STRING HERE"): string.Empty %>

    More information:

    DateTime.ToString Method (String)

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, July 12, 2016 9:48 AM

  • It could be achieved by setting the "LocaleId" attribute of the DateTimeField.

    Also you can disable time display by setting “DateOnly” attribute to True.

    <SharePointWebControls:DateTimeField FieldName="4aaf3b75-d54b-4198-b100-bd3aee42224a" LocaleId="1052" DateOnly="true" runat="server" />

    LocaleId=“1052” stands for the format which is you want.

    There are some other LocaleId for the date format, please refer:



    http://technet.microsoft.com/en-us/library/cc824907(v=office.14).aspx#BKMK_LocaleIDs


    you can see list properties 
    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.datetimefield_properties.aspx
    Wednesday, July 13, 2016 3:54 PM