Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i have an asp.net web application in which i have a page where i have date textbox,
whenever i'm trying to convert the textbox text to datetime, its throwing error,
Error
for hijri date, error: String was not recognized as a valid DateTime.

for grogorian date error: The Date Time represented by the string is not supported in calendar System.Globalization.GregorianCalendar.

*Not able to convert any date.


What I have tried:

Convert.ToDateTime(txtDOB.Text, CultureInfo.GetCultureInfo("en-US").DateTimeFormat);


When i have bind the textbox on pageload
textbox.text = DateTime.Now.ToShortDateString();
then, i'm getting here is, hijri date.

Error:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Conversion:
Convert.ToDateTime(txtDOB.Text, CultureInfo.GetCultureInfo("ar-SA").DateTimeFormat);


Can anyone please help me, how to solve this.


Thanks
Posted
Updated 26-Jun-16 22:10pm
v2
Comments
[no name] 27-Jun-16 6:29am    
Probably this will solve your problem : http://stackoverflow.com/questions/11189807/cannot-convert-from-hijri-date-to-gregorian-date-c

MS does have support for hijri calendars HijriCalendar Class (System.Globalization)[^] ... Matt Johnson's answer here on SO may help if you're trying to do hijri <-> Gregorian conversion ..

I know one thing .. the 'en-US' here

Quote:
Convert.ToDateTime(txtDOB.Text, CultureInfo.GetCultureInfo("en-US").DateTimeFormat);


would be wrong
 
Share this answer
 
Comments
abdul subhan mohammed 27-Jun-16 5:08am    
i have tried with en-US as well, but the error is same
 
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