Kourosh
Kourosh

Reputation: 789

PersianDateCalendar and Exception

I have a problem with PersianDateCalendar class and ArgumentOutOfRangEexception... here is my code :

DateTime get = Convert.ToDateTime(TextBox.Text);
PersianCalendar p = new PersianCalendar();
DateTime set = new DateTime(p.GetYear(get), p.GetMonth(get), p.GetDayOfMonth(get));

for some dates it's working and for some it's not working!!!! for example when I write 7/22/2006 or 5/20/2006 it throw an ArgumentOutOfRangeException... I know what is this Exception and what it means.. but the problem is it's not out of range in real world!!! is it??? Have I done something wrong?? or is it a bug in class?

Upvotes: 0

Views: 66

Answers (2)

AliJP
AliJP

Reputation: 678

I had this problem too. It's because when you are converting to Persian date, your result is ..../../31 and some of Gregorian calendar's months don't have 31st day. you should return your result as a string instead of DateTime.

Upvotes: 1

dblk1965
dblk1965

Reputation: 132

check your culture, looks like it treats it as dd/mm/yyyy

Upvotes: 0

Related Questions