overriding date format settings dynamically from .mrt files

Stimulsoft Reports.WEB discussion
Post Reply
nilesh8600
Posts: 19
Joined: Tue Feb 16, 2016 10:16 am

overriding date format settings dynamically from .mrt files

Post by nilesh8600 »

Hi,

I have one query regarding over writing the date time format dynamically, if we have already set something in the .mrt files as follows.
I want to set the date format as dd/MM/YYYY dynamically.

Below is the date format setting from .mrt file which we want to override dynamically:

<Text>Ending Date: {rpt.EndDate.ToString("MM/dd/yyyy")}</Text>

OR

<value>Formulas,fxOrderDate,fxOrderDate,System.String,GetCompanyAddress.dateFormat_x0020__x003D__x003D__x0020__x0022_Italian_x0022__x000D__x000A__x003F_rptPoForm.PODATE.ToString_x0028__x0022_dd-MMMM-yyyy_x0022__x0029__x000D__x000A_:rptPoForm.PODATE.ToString_x0028__x0022_MM_x002F_dd_x002F_yyyy_x0022__x0029_,True,True</value>

So, in short please let me know if we can over write the above settings dynamically by the date format we want, without changing .mrt file. Might be like doing some changes at back end etc.,

Thanks,
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: overriding date format settings dynamically from .mrt fi

Post by Alex K. »

Hello,

Please try to use the Culture property for the report. You can set the necessary culture before render report.

Thank you.
nilesh8600
Posts: 19
Joined: Tue Feb 16, 2016 10:16 am

Re: overriding date format settings dynamically from .mrt fi

Post by nilesh8600 »

this.GlobalizationManager.Culture = CultureInfo.CurrentCulture;

Is this the correct way? I'm trying it and will share my results. Please let me know if I need to do anything else other than what I'm doing.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: overriding date format settings dynamically from .mrt fi

Post by HighAley »

Hello.

Here is the code that set the Culture property of the report:

Code: Select all

this.Culture = "en-US";
Thank you.
nilesh8600
Posts: 19
Joined: Tue Feb 16, 2016 10:16 am

Re: overriding date format settings dynamically from .mrt fi

Post by nilesh8600 »

I tried to set the culture property as shown below, but it failed to override the date format settings from .mrt file.

Initially I tried to set below property,

this.GlobalizationManager.Culture = new CultureInfo("ms-MY");

Also followed the way you suggested,

this.Culture = "ms-MY";

this.GlobalizationManager.Culture, has properties like datetime format and I was able to see that the culture I set was reflecting correctly in Culture object (i.e., "ms-MY" with date format as dd/MM/yyyy ), but the end result was not changed and the date displayed was in MM/dd/yyyy format.

Please help me as I'm running out of time.
nilesh8600
Posts: 19
Joined: Tue Feb 16, 2016 10:16 am

Re: overriding date format settings dynamically from .mrt fi

Post by nilesh8600 »

When I change the below line in .mrt file,

<Text>Ending Date: {rpt.EndDate.ToString("MM/dd/yyyy")}</Text>

To

<Text>Ending Date: {rpt.EndDate}</Text>

The culture setting gets applied and the EndDate field gets displayed in the desired format. I think as we have set the field as to string, the culture property doesn't change it.

As we have lot of reports and changing the reports one by one is not feasible, please suggest the best way to override the date format dynamically without having changes in the .mrt files.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: overriding date format settings dynamically from .mrt fi

Post by HighAley »

Hello.

Here are results of rendering next expression:

Code: Select all

Today: {Today}
{this.Culture}
us.png
us.png (2.03 KiB) Viewed 6597 times
de.png
de.png (1.96 KiB) Viewed 6597 times
The Culture property works as expected.
Could you specify which version of our product you use?

Thank you.
nilesh8600
Posts: 19
Joined: Tue Feb 16, 2016 10:16 am

Re: overriding date format settings dynamically from .mrt fi

Post by nilesh8600 »

Hello,

Yes, you are correct. But does it works even if the date field is set as a string expression in the .mrt file as I have mentioned above?

I'm using Stimulsoft's Reports.Web Reporting Tool for ASP.NET MVC.

Thanks,
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: overriding date format settings dynamically from .mrt fi

Post by HighAley »

Hello.

If the DateTime is passed to the report as string in should be in right format.
It should correspond the Culture or be in ISO 8601 format.
If you change Culture, but the date is in format from different Culture it will not parsed right.
Please try to use the ISO 8601 format.

Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: overriding date format settings dynamically from .mrt fi

Post by HighAley »

Hello.

Anyway if you set the custom format with ToString method you should change it.
Maybe you could use next format specifier:
<Text>Ending Date: {rpt.EndDate.ToString("d")}</Text>

or you could specify date format in GlobalizationManager.

Thank you.
Post Reply