strange errror while parsing string to datetime in c#
-
hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.
-
hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.
Sounds like it's not using the Farsi calendar... In our calendar (Whatever you call it), 1388/02/30 would parse to February 30th, 1388... Since 1388 is a leap year, that month has 29 days. Make sure you're using the right DateTimeFormatInfo in the parsing function.
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)
-
hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.
I think these might help: Persian Calendar [^] Persian Calendar Members[^] The references refer to a type that is specifically designed for handling Persian dates as the month lengths are incompatable with Gregorian dates (ie xxxx/02/31 is valid). You will most probably need to convert to a standard
DateTime
(there is a ToDateTime method) when saving to database, otherwise you are in for a world of pain trying to get it to work.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks