Did you know that different countries have different date formats? When you make a multilingual report, or a report for a country where they speak Persian (Farsi), it is important to bring up dates in the correct format. By default, FastReport uses the European date format, but the .NET tools allow converting it into different formats.
Thus, our task is to convert the date into the Persian format. For example, our report has an expression [Date], bringing up today’s date:
The expression [Date] gets the current system date in the DateTime format, but the value of the text report after all processing is the String. Let us create a new function in the report script:
We will evoke this function from text objects. We create a temporary variable, which will convert the text of the object into DateTime:
“sender as TextObject” is the address to the object which evoked the function. We may use the functions and properties of an object if we address it in such a way.
After that, we will need the PersianCalendar object, which will convert the date into the Persian format:
Note that this object is stored in the System.Globalization library, and it must be indicated in the “using” section.
Then we must change the text of the object. Consider this line in more detail:
Here we set the text of our object. The value will be in the format year/month/day, because we use the functions of the PersianCalendar which get the respective values. The code section where the text is set can be edited as you wish. For example, the code for the date in the day.month.year format looks like this:
As a result, we get the following function:
Add the function to the AfterData event of the relevant object.
Now the date looks like this:
To use other functions related to time, you can consult the following table:
|GetDayOfWeek(),||Day of week|
|GetDayOfMonth(),||Day of month|
Now you know how to change the format of date in your report. This article may help in changing the format to (year, month, day). This format is used in Japan, China, North Korea, South Korea, Taiwan, Hungary, Lithuania, and Iran; also, it is used as a collateral one in some European and Asian countries.