+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / Blog Date formatting

Blog Date formatting

9 posts, 0 answered
  1. Amar Galla
    Amar Galla avatar
    2 posts
    Registered:
    08 Sep 2009
    02 Jul 2010
    Link to this post
    I am now extremely frustrated with this and would love some help. I am trying to format the blog date as outlined in the Telerik TV webcast to DateFormatString="MMMM '<strong>'dd'</strong>' "

    However, I keep getting String was not recognised as a valid datetime error. I found a thread on this forum which hinted to add a list item entry for the format to the TextSettingTemplate.ascx file, however that does not help too. It just will not take this format. I even tried a simple format as DateFormatString="dd" or DateFormatString="ddMMMM" and strangely that too gives an error. The following formats have worked :

    DateFormatString="d" and DateFormatString="MMMMd"

    This ridiculously flawed. It does not fully accept the Microsoft Datetime formatting options and nor does it work with the formatting example shown in Sitefinity's own webcast.

    Can anyone help? I am relatively new to Sitefinity but have been developing with ASP.NET for a long time.

    Regards,
    Amar
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Jul 2010
    Link to this post
    Hi Amar Galla,

    This error appears if a string is interpreted as a standard format string, but does not contain one of the standard format specifiers, then a FormatException is thrown. Such errors are thrown by .NET Framework method DateTime.Parse Method.
    You can perform a simple test on the problematic server where you pass the date format to DateTime.Parse Method and see what will be returned as a result.

    Here is a link with the standard DateTime format strings MSDN

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Amar Galla
    Amar Galla avatar
    2 posts
    Registered:
    08 Sep 2009
    02 Jul 2010
    Link to this post
    Thanks Ivan. I did have a look at the standard codes. What I am trying to achieve is exactly same as what was shown in the Telerik webcast video. How was that done? I am using exactly the same formatting string that was used, so what other settings / changes I need to do for that to work?

    Regards,
    Amar
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Jul 2010
    Link to this post
    Hi Amar Galla,

    I am not sure whether you tried my suggestion before responding to this.  Have you tried to call DateTime.Parse in a sample code? You will get not recognized format error form ASP.NET Framework, because the DateFormatString you are trying to use is not valid.

    <telerik:DateTimeLiteral ID="testDate" runat="server" DateFormatString="ddMMMM" />


    testDate.Date = DateTime.Now;
    DateTime parsed = DateTime.Parse(testDate.ToString());

    Data time formatting is handled by .NET Framework

    Solution

    • Crate a custom ContentView based control where you will parse the date by passing it to custom IFormatProvider Interface provider.


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Luke Horan
    Luke Horan avatar
    20 posts
    Registered:
    02 May 2010
    31 Aug 2010
    Link to this post
    Hi I'm having a similar problem with displaying a blog list with the  publication date being shown,
    The date looks fine in the backend admin side but causes the below error when it tries to publish to the front end page.
    if i display it as a literal it displays as 12/11/YYYY
    Any ideas??

    Server Error in '/' Application.
    The string was not recognized as a valid DateTime. There is a unknown word starting at index 6.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 6.
     
    Source Error:
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     
    Stack Trace:
     
    [FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 6.]
       System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +2838082
       System.DateTime.Parse(String s) +25
       Telerik.Cms.Web.UI.DateTimeLiteral.set_Text(String value) +95
       Telerik.Cms.Engine.WebControls.Design.Settings.TextSettingService.ApplySettings(ContentView sender, BaseSettingValue settingValue, Control container) +698
       Telerik.Cms.Engine.WebControls.ContentView.ApplyModeSettings(List`1 settings, Control container) +191
       Telerik.Cms.Engine.WebControls.ContentView.repeater_ItemDataBound(Object sender, RepeaterItemEventArgs e) +712
       System.Web.UI.WebControls.RepeaterItemEventHandler.Invoke(Object sender, RepeaterItemEventArgs e) +0
       System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +108
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +136
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +443
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
       System.Web.UI.WebControls.Repeater.DataBind() +75
       Telerik.Cms.Engine.WebControls.ContentView.CreateChildControls() +5666
       Telerik.Blogs.WebControls.BlogPosts.CreateChildControls() +37
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    31 Aug 2010
    Link to this post
    Hi Luke Horan,

    Have you tried to parse the string manually by using DateTime.Parse Method. ? Also string representations of date and time values typically vary by culture. Please check - Standard Date and Time Format Strings

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Luke Horan
    Luke Horan avatar
    20 posts
    Registered:
    02 May 2010
    31 Aug 2010
    Link to this post
    I would love to have control to be able to use the datetime.parse but without having to rewrite the blog module I don't have access to call that.
    The blog repeater is assigning the value directly to the control from the metavalues.

    what culture does sitefinity use so I can change the server so that sitefinity will be able to display the date.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    31 Aug 2010
    Link to this post
    Hi Luke Horan,

    It is not required to override anything you have to check in a basic control whether the format is valid. As you can see in the other posts I have provided a sample code for this. We do not set the culture when the format is parsed. This depends on the server culture and ASP.NET Framework on your server.  We set the Date value of DateTimeLiteral to  DateTime and if there is a DateFormatString we set the value

    dateLit.DateFormatString = DatesFormat;
    dateLit.Date = (DateTime)obj;

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Luke Horan
    Luke Horan avatar
    20 posts
    Registered:
    02 May 2010
    31 Aug 2010
    Link to this post
    in the blog user control I have the date format set as "01 Sep 2010" with the date checkbox checked
    the ContentViewItemList aspx is as default and in the repeater
                    <telerik:DateTimeLiteral ID="Publication_Date" runat="server"  DateFormatString="d" />

    I've tried accessing the publication_date by creating a code behind page and trying to access the data onItemDatabound but can't get access to the object. for something that should be sorted in 15 seconds i've wasted 6 hours trying to get a fix or workaround.

    Just getting so frustrated as a number of the other check boxes don't work either with blogs when you switch categories or tags off. the headings still appear. so I've had to write some code to clean that up.
Register for webinar
9 posts, 0 answered