Page 1 of 1
overriding date format settings dynamically from .mrt files
Posted: Tue May 17, 2016 2:47 pm
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,
Re: overriding date format settings dynamically from .mrt fi
Posted: Wed May 18, 2016 7:48 am
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.
Re: overriding date format settings dynamically from .mrt fi
Posted: Wed May 18, 2016 5:16 pm
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.
Re: overriding date format settings dynamically from .mrt fi
Posted: Thu May 19, 2016 8:38 am
by HighAley
Hello.
Here is the code that set the Culture property of the report:
Thank you.
Re: overriding date format settings dynamically from .mrt fi
Posted: Thu May 19, 2016 10:31 am
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.
Re: overriding date format settings dynamically from .mrt fi
Posted: Thu May 19, 2016 1:51 pm
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.
Re: overriding date format settings dynamically from .mrt fi
Posted: Fri May 20, 2016 12:01 pm
by HighAley
Hello.
Here are results of rendering next expression:

- us.png (2.03 KiB) Viewed 6600 times

- de.png (1.96 KiB) Viewed 6600 times
The Culture property works as expected.
Could you specify which version of our product you use?
Thank you.
Re: overriding date format settings dynamically from .mrt fi
Posted: Fri May 20, 2016 1:07 pm
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,
Re: overriding date format settings dynamically from .mrt fi
Posted: Fri May 20, 2016 2:28 pm
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.
Re: overriding date format settings dynamically from .mrt fi
Posted: Fri May 20, 2016 2:43 pm
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.