Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i use select command for datetime field,display value is incorrect.my system currentculture is 'fa-IR' and i use DateTime.Now for insert into database field.

What I have tried:

i use calender for convert datetime between persian and english calender.
Posted
Updated 3-Jun-20 20:44pm
Comments
F-ES Sitecore 21-May-20 6:05am    
As long as you keep the field as a date in SQL and a DateTime in .net then you can use the ToString method of your DateTime variable to show the date in your desired format, or if you are using a calendar component then there should be a property somewhere that allows you to set the desired format.
Maciej Los 21-May-20 8:21am    
Show your code!

Using the following solution You can work with DateTime and display it without getting an exception:

C#
class YourProgram
{
	static void Main(string[] args)
	{
		CultureInfo cinfo=new CultureInfo("fa-Ir");
		cinfo.DateTimeFormat.Calendar=new ParsianCalender();
		Thread.CurrentThread.CurrentCulture=cinfo;
		string str=DateTime.Now.ToString("yyyy/MM/dd");
	}
}
 
Share this answer
 
v2
Comments
Richard Deeming 4-Jun-20 6:27am    
How is this supposed to be a solution to the question of storing dates in a database?
SQL databases actually store and treat DateTime values as numerical values.

How these are displayed is up to the individual SQL Client; it may inherit it from the Operating System or it may have it's own setting for it.
If you are using SQL Server Management Studio, the settings are located within
Tools > Options... > Environment > International Settings > Language
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900