Format Date in Expression of HTML Textbox Control

6 posts, 0 answers
  1. Steven
    Steven avatar
    2 posts
    Member since:
    Jul 2015

    Posted 16 Feb 2018 Link to this post

    I am trying to build a string of multiple fields with line breaks and a formatted date.  However I cannot get the Format function to work.  Here is what I have

    {Fields.title}<br />Since<br />Format('{0:MMM yyyy}', {Fields.StartDate})

    Trying to get output like

    CEO

    Since

    March 2010

  2. Silviya
    Admin
    Silviya avatar
    331 posts

    Posted 21 Feb 2018 Link to this post

    Hello Steven,

    Function Format(format, value) formats the value using the specified format string (check here).
    Detailed information about date and time format specifiers can be found in 
    Standard Date and Time Format Strings and Custom Date and Time Format Strings MSDN articles.

    The formatting of a date directly in the HtmlTextBox expression, could be done by using ToString("MMMM yyyy"). Basically the whole expression has to include the following in order to show the desired output: 

    {Fields.title}<br />Since<br />{Fields.StartDate.ToString("MMMM yyyy")}

    Regards,
    Silviya
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Silviya
    Admin
    Silviya avatar
    331 posts

    Posted 22 Feb 2018 Link to this post

    Hello Steven,

    As a follow up from my last answer, there is another approach that would evaluate the same date format by using Embedded Expressions:

    {Fields.title}<br />Since<br />{Format('{{0:MMM yyyy}}', Fields.StartDate)}

    Note that curly brackets are special symbols, and  should be escaped with double brackets like this: {{ or }}.

    On the other hand, if you have a new item only for the date field, it can be used with an expressionTo specify that is an expression, the value should be a string starting with equal (=) sign like the following:

    =Format('{0:MMM yyyy}', Fields.StartDate)

    Regards,
    Silviya
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
  4. Dana
    Dana avatar
    3 posts
    Member since:
    Mar 2014

    Posted 15 Feb in reply to Silviya Link to this post

    Silviya,

    The examples you have provided are not working for me. I am attempting to output the short date string of a report parameter in the header of the report. I am using an HtmlTextBox

    By default I can get the long date time to display by simply calling

    Date: {Parameters.Date.Value}

    To achieve the short date time string I have tried

    ={Format('{{0:mm/dd/yyyy}}', Parameters.Date.Value)}
     
    Date: {Format('{0:d}', Parameters.Date.Value)}
     
    Date: {Parameters.Date.Value.ToString("mm/dd/yyyy")}
     
    Date: {Parameters.Date.Value.ToShortDate()}

    Basically attempting to display the users chose parameters in the Report Header, can you guide me to the right approach?

     

  5. Dana
    Dana avatar
    3 posts
    Member since:
    Mar 2014

    Posted 15 Feb in reply to Dana Link to this post

    It seems that this might work (modified from answer found at: format datetime inside HTMLTextBox expression - remove seconds)

    Date: {Format('{{0:M/dd/yyyy}}', Parameters.Date.Value)}
  6. Silviya
    Admin
    Silviya avatar
    331 posts

    Posted 19 Feb Link to this post

    Hi Dana,

    I'm happy to hear that you've found a solution. Let us know if you need further help.

    Best,
    Silviya
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top