I'm using the below code to detect the correct Persian date format.
var formats = new[] { "yyyy/d/M", "yyyy/M/dd", "yyyy/MM/d", "yyyy/MM/dd" };
DateTime dt;
if (!DateTime.TryParseExact(date, formats, null, DateTimeStyles.None, out dt))
{
correctedDate = date.FixDate();
}
else
{
correctedText = date;
}
The point is that there will be problems with some specific dates e.g. "1400/02/29".
I've tried different CultureInfo
and also DateTimeStyles
but I still get the same result.