Persian Calendar in the Report

2021-05-19

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:

[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:

private void ConvertToPersianDate(object sender, EventArgs e)

We will evoke this function from text objects. We create a temporary variable, which will convert the text of the object into DateTime:

DateTime d = DateTime.Parse((sender as TextObject).Text);

“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:

PersianCalendar pc = new PersianCalendar();

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:

(sender as TextObject).Text = string.Format("{0}/{1}/{2}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d));

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:

"{0}.{1}.{2}", pc.GetDayOfMonth(d), pc.GetMonth(d), pc.GetYear(d)

As a result, we get the following function:

using System.Globalization;
namespace FastReport
{
 public class ReportScript
 {
 private void ConvertToPersianDate(object sender, EventArgs e)
 {
 // Converting to DateTime format
 DateTime d = DateTime.Parse((sender as TextObject).Text);
 
 // Creating an object for conversion
 PersianCalendar pc = new PersianCalendar();
 
 // Creating a string using PersianCalendar
 // It is possible to change the string template
 (sender as TextObject).Text = string.Format("{0}/{1}/{2}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d));
 }
 }
}

Add the function to the AfterData event of the relevant object.

AfterData

Now the date looks like this:

Final result

To use other functions related to time, you can consult the following table:

 GetDayOfWeek(),  Day of week
 GetMonth(),  Month
 GetDayOfMonth(),  Day of month
 GetYear(),  Year
 GetHour()  Hour
 GetMinute()  Minute
 GetSecond()  Second

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.

.NET .NET FastReport FastReport
10 Kasım 2026, Salı

FastReport Online Designer'a kendi bileşeninizi nasıl eklersiniz

Aprenda a adicionar um componente personalizado ao FastReport Online Designer: crie um plug-in em JavaScript com uma visualização e uma caixa de diálogo de configurações e, em seguida, conecte a classe .NET do lado do servidor.
26 Ekim 2026, Pazartesi

Delphi’de İlerleme Çubuğu: FastReport VCL’den TfrProgressBar ve TfrxProgressBar Bileşenleri

FastReport VCL'deki TfrProgressBar ve TfrxProgressBar bileşenlerini daha yakından inceleyelim: ilerleme ölçeğini, eşik değerlerini ve işaretçileri yapılandırma, verilere bağlama ve bir Delphi örneği.
26 Ekim 2026, Pazartesi

TfrImageComboBox: FastReport VCL’de resim ve metin başlıklarını içeren bir açılır liste

FastEditors VCL'den TfrImageComboBox: FastReport VCL için simgeler ve etiketler içeren bir açılır liste. Delphi'de özellikler, olaylar ve kullanım örnekleri.

© 1998-2026 Fast Reports Inc.