Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 10, 2011 06:21 PM by konanki
Aug 10, 2011 09:42 AM|LINK
I have a textbox on a page where user fills date in DD/MM/YYYY format.
I need to insert this date in a SQL table column, where date format is sql Datetime (e.g. 10/1/2007 12:00:00 AM)
How do i convert c# string to this format ?
I am getting this error while executing insert command : "String was not recognized as a valid DateTime."
Please help on this.
Aug 10, 2011 09:48 AM|LINK
hi frnd you can use
or ensure that u enter valid date or not.
Aug 10, 2011 09:51 AM|LINK
Hi use this code
public static DateTime DateParse(string date)
date = date.Trim();
return DateTime.Parse(date, new System.Globalization.CultureInfo("en-GB"));
return new DateTime();
Aug 10, 2011 09:52 AM|LINK
Thnx Dude. It worked.
So simple it was.
Aug 10, 2011 10:40 AM|LINK
Everything is correct except that it is giving me format : mm/dd/yyyy instead of dd/mm/yyyy.
Can it be corrected ?
Aug 10, 2011 10:55 AM|LINK
I solved it by myself.
Instead of using en-GB, i tried en-US and it gave the correct format.
Aug 10, 2011 04:53 PM|LINK
I observed an unusual behavior with this solution. It works fine when input date is 03/07/2011, but it gives "String was not recognized as a valid DateTime."
error when input date is 13/07/2011. What could be the reason for it and how do I solve it ?
Aug 10, 2011 06:21 PM|LINK
in insert statement you can convert database datetime.