This is a migrated thread and some comments may be shown as answers.

Format Date in Expression of HTML Textbox Control

5 Answers 2797 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 16 Feb 2018, 07:17 PM

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

5 Answers, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 21 Feb 2018, 05:08 PM
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
2
Silviya
Telerik team
answered on 22 Feb 2018, 09:20 AM
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
0
Dana
Top achievements
Rank 1
answered on 15 Feb 2019, 07:06 PM

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?

 

0
Dana
Top achievements
Rank 1
answered on 15 Feb 2019, 07:24 PM

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)}
0
Silviya
Telerik team
answered on 19 Feb 2019, 11:36 AM
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
Tags
General Discussions
Asked by
Steven
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Dana
Top achievements
Rank 1
Share this question
or