Date format - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Date format

  • Date format
  • How do I format the event date and time to say (for example):

    June 5, 2011 1:00 pm

    <sf:FieldListView ID="EventStart" runat="server" Format="EventStart.ToLocal():MMM dd, yyyy HH:mm" runat="server" />

    Also, is there a way to get a custom field to show using the sf:FieldListView control.  For example, I added a custom field called "Cost" and I'd like it to show in the template along with dates, address, contact, etc.
  • Hi Amanda Shafer,

    If you want to implement 12h time format with AM/PM designation please use the below sample.

    <sf:FieldListView ID="EventStart" runat="server" Format=" | EventStart.ToLocal():MMM dd, yyyy hh:mm tt" />
    Concerning using your custom field in a template, please try including it like this:
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Cost")%>' />
    I hope this information helps, if you have any further questions, please let us know.
    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Thank you, Boyan.

    Next question is whether anyone has been able to do the following. We have a mix of events that occur on one day and those that last two or three. I'm trying to find a good way to get the dates to format to make this clear.

    I could do a field for start date and one for end date, but then when the event is on one day it is redundant.  But I can't just use the start date because some last more than one day.

    I tried adding an event with no end date, but then it doesn't display on my list at all.

    I'd to have a way to say Date: June 10, 2011   for single day events and  Date: June 10 - 15, 2011 for multiple dates.

    Has anyone acheived something similiar to this?

  • 273801_EventsDates.PNG
    Hi Amanda Shafer,

    The functionality you demand is implemented in the default template we're using for Events - if it's a one day Event we're displaying only that date (e.g. Dates: 26 May, 2011) if it's a several day Event we're displaying EventStart and EventEnd dates (e.g. Dates: 25 – 25 May, 2011). Please refer to the attached screenshot for more information. I'm pasting the default template below as well:

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <telerik:RadListView ID="eventsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
            <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add"></sf:ContentBrowseAndEditToolbar>
            <ul class="sfeventsList sfeventsListTitleCityDate">
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li class="sfeventListItem">
                <h2 class="sfeventTitle">
                    <sf:DetailsViewHyperLink TextDataField="Title" ToolTipDataField="Description" runat="server" />
                </h2>
                <div class="sfeventMetaInfo">
                    <sf:FieldListView ID="where" runat="server"
                        Text="0 | " Properties="City"   />
                    <sf:FieldListView ID="EventsDates" runat="server" />
                    <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfeventCommentsCount"/>
                </div>
                <sf:ContentBrowseAndEditToolbar ID="BrowseAndEditToolbar" runat="server" Mode="Edit,Delete,Unpublish"></sf:ContentBrowseAndEditToolbar>
            </li>
        </ItemTemplate>
    </telerik:RadListView>
    <sf:Pager id="pager" runat="server"></sf:Pager>
    I hope this information helps you achieve the desired functionality. If you have any further question, please do not hesitate to ask.

    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,
    Thank you! How do I format it so that it's as follows: March 11 - 12, 2010 as opposed to day, month, year?  I tried
    EventStart.ToLocal():MMM dd, yyyy  but that doesn't seem to have any effect.
  • Hi Amanda Shafer,

    Thank you for getting back to me. Let's just clarify one thing, so that I'm sure we're on the same track here - the end result that you want to be displayed on the frontend page should be:
    1) One day events: ''Dates: 26 May, 2011"
    2) Multiple days events: "Dates: 25 – 27 May, 2011"
    or you'll also need to display the hours as well?
    The reason why I'm asking you this question, is that if you won't need to display the hours at all, you can simply leave the EventEnd field empty, which will display single date for single days events, and Start-End dates for multiple days events using :
    <sf:FieldListView ID="EventsDates" runat="server" />
    If you need to display the hours as well, then you'll have to use
    <sf:FieldListView ID="EventStart" runat="server" Format="  EventStart.ToLocal():MMM dd, yyyy hh:mm tt" />
     <sf:FieldListView ID="EventEnd" runat="server" Format=" - EventEnd.ToLocal():dd, yyyy hh:mm tt" />
    Please let me know if the suggested solutions differ from what you desire to achieve as end functionality, so that I can advise you further.

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hello Boyan,

    The hours are not important. However, I do need it to format with Month, Day, Year. The default you provided is Day Month Year.

    When I leave the end date empty, the event does not appear at all on the page.

    Thanks!
  • 274492_Events-Format-DMY.PNG
    Hi Amanda Shafer,

    Thank you for the clarification. The second option I've listed in my last response does set the format to MMM/DD/YYYY, you might use it in your template instead of the FieldLIstView control. I'm pasting below a refined version which does not display the extra "-" when the event is a single day event.

    <sf:FieldListView ID="EventStart" runat="server" Format="  EventStart.ToLocal():MMM dd, yyyy hh:mm tt" />
     <sf:FieldListView ID="EventEnd" runat="server" Format="  EventEnd.ToLocal(): '\-' MMM dd, yyyy hh:mm tt" />
    Please take a look at the attached screenshot as well, which shows how this change int he template affects the frontend rendering of Events. It displays both events that have to EventEnd date set, ones that end the same day (although I personally believe if the event will end the same day there'd be no need to fill in the End date; and a multiple days Event) If you have any further questions, please don't hesitate to ask. It was a pleasure for me to help you.

    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • I am having issues with the single day event. If its a single day event, I only put in the event start date. When I remove the date from event end and save it, it puts the event start date back in the event end date field so my screen looks like

    sample event
    June 9  -  9 2011

    please advice.

    Thanks
  • Hello nana,

    Could it be that you're using an older version of Sitefinity, as I've tested this functionality with our latest release version and I was not able to reproduce the mentioned issues. If so, please let me know which build version you're using so I can inspect this issue further. Thanks in advance!

    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Standard Edition

    Build 4.0.1098.0

    License details

    Edition:
    Standard Edition


    And the required checkbox is not checked for enddate either.

    Thanks
    Nana
  • Hello nana,

    Thank you for the clarification. Indeed we have changed the logic for using EventStart and EventEnd dates, as I have just observed myself the date is automatically filled in the older version, so the template provided to Amanda would not work on your project as long as you do not upgrade to the newer version. However, please let me know of the use case scenario you want to implement, maybe we can come up with some workaround.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Simply,
    there are events on single days and events on multiple days

    the events that are single days I want displayed as e.g. June 9 2011  and for multiple days it should be displayed as June 9  - 11 2011.

    I am using the widget templates. but as i said, the single day ones are displaying  June 9 - June 9 2011 because there is no way not to set the end date or leave blank
  • Hello nana,

    I'll try to come up with a sample that implements this functionality on your template, however I'd recommend you to consider upgrading your project to the newer version, not only will you benefit from getting the desired behavior out-of-the-box, but also you will get all the new functionality and fixes we've introduced. Please get back to me if you still prefer to use the current version, so I can try to provide you with some workaround.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items