tags:

views:

20

answers:

1

hi friends. I have a datagrid which populated by some data from sqlserver.I have datetime filed that represent Georgian date,but i want to convert this to Persian by using PersianCalendar. I wan some kind of conversion, that gets Georgian date from database but when it comes to show on datagrid or some where else, it shows persian date.

A: 

For formatting you need to use the appropriate CultureInfo class, not the calendar - the names of persian cultures are fa or fa-IR, as can be seen here.

CultureInfo farsi = new CultureInfo("fa-IR");
farsi.DateTimeFormat.Calendar = new PersianCalendar(); 
DateTime date1 = new DateTime(1867, 1, 1);

Console.WriteLine(date1.ToString(farsi));

Update:

You can use the ItemDataBound event of the grid in order to format the date exactly as you want.

Oded
how can i use this in datagrid view or some other places in asp.net ?
persian Dev
@persian Dev - You need to set the thread culture of the app (UI thread if a winforms app), to the Persian culture. http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
Oded
thank you dear Oded
persian Dev
i used <globalization culture="fa-IR" /> but the date format does not change to persian format.
persian Dev
@persian Dev - Did you also set the `uiCulture="fa-IR"`?
Oded
use i have used it, but just changed the direction of error pages as i see.
persian Dev
@persian Dev - Are you using winforms or webforms or wpf?
Oded
i am using webforms, ASP.NET 3.5
persian Dev