Here is where documentation is your friend:
PersianCalendar Class
DateTime Constructor (Int32, Int32, Int32, Calendar)
This is the exact code you'd need:
PersianCalendar p = new System.Globalization.PersianCalendar();
DateTime today = DateTime.Today;
DateTime pDate = new DateTime(p.GetYear(today), p.GetMonth(today), p.GetDayOfMonth(today), p);
DateTime d2 = DateTime.Parse(textBox9.Text);
// THIS NEEDS TO BE EXPLAINED
textBox10.Text = (d2 - pDate).ToString().Replace(".00:00:00","");
Ultimately, what are you trying to do? What are the results you're expecting in textBox10
? If you want the number of days between the two dates, then just do (d2 - pDate).ToString("d")
and you'll get the difference in days. Maybe if you explained a little further WHAT you're trying to do, instead of HOW you're trying to do it, we can possibly help you further.
Edit: Just realized what comecme was saying. The line that would cause the issue is here:
DateTime d2 = DateTime.Parse(textBox9.Text);
Instead, we would need to change it to also use the culture information as well:
CultureInfo persianCulture = new CultureInfo("fa-IR");
DateTime d2 = DateTime.Parse(textBox9.Text, persianCulture)
Edit: You are correct, it only allows parsing the date in the Persian format, but does not validate according to a particular calendar. In order to get this working properly, you're gonna have to manually parse out the date and instantiate a new DateTime with the PersianCalendar supplied:
DateTime d2;
if(Regex.IsMatch(textBox9.Text, "^dddd/dd/dd$"))
{
d2 = new DateTime(
int.Parse(textBox9.Substring(0,4)),
int.Parse(textBox9.Substring(5, 2)),
int.Parse(textBox9.Substring(8, 2)),
p);
}
You just have to make sure that the input definitely matches the format you specify, otherwise there's no way to consistently parse out the DateTime accurately.