More in this section
Forums / Developing with Sitefinity / Date formatting not applying correct

Date formatting not applying correct

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Andrew Booth
    Andrew Booth avatar
    21 posts
    Registered:
    20 Jul 2009
    07 Apr 2011
    Link to this post
    I am using this:

    <telerik:DateTimeLiteral runat="server" ID="Event_Start" DateFormatString="d">
                    </telerik:DateTimeLiteral>

    and the format it is applying is "4/14/2011". It should ONLY display the day. Why is "d" showing the full date?

    Also when I change "d" to "dd" or "ddd", it errors out and says Input string not in correct format...

    Any ideas?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Apr 2011
    Link to this post
    Hello Andrew,

    The control works with the standard DateTime format

    http://msdn.microsoft.com/en-us/library/az4se3k1%28v=vs.71%29.aspx

    You can customize the ListPageMaster template and set a label with a custom format

    sample

    <script type="text/C#" runat="server">
      
         public void Page_Load(object sender, EventArgs e)
         {
             this.repeater.ItemDataBound += new RepeaterItemEventHandler(repeater_ItemDataBound);
         }
     
         void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
         {
             if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
             {
                 var cntrl = (Literal)e.Item.FindControl("Event_End");
                 if (cntrl != null)
                 {
                     var content = (Telerik.Cms.Engine.IContent)e.Item.DataItem;
                     if (content != null)
                     {
                      var date = (DateTime)content.GetMetaData("Event_Start");
                      var ds = date.ToString("M.d.yyyy h:mm tt");
                      cntrl.Text = ds;
                     }
                 }
             }
         }    
          
    </script>


    Best wishes,
    Ivan Dimitrov
    the Telerik team

  3. Scott
    Scott avatar
    4 posts
    Registered:
    27 May 2010
    07 Apr 2011
    Link to this post
    Ivan - 

    That makes sense now. I was under the impression it worked with custom formats as well outside of the standard ones.

    I'll create a custom format with some coding then.

    Thanks!
Register for webinar
3 posts, 0 answered