I'm using Ajax date picker control ....I'm showing selected date like dd/mm/yyyy .This is working very fine but some times suddenly it showing error like
"String was not recognized as a valid DateTime" .Now also I'm able to use the date picker without any error in local after publishing in Server some times it showing the above error ...why???cn any one help me plz???
priya AvanigaddaPosted Nov 12, 2014, 5:28 AM
Abhay ShankerPosted Nov 12, 2014, 5:19 AM
DateTime.ParseExact(finalList, "dd/MM/yyyy", CultureInfo.InvariantCulture)
or
DateTime.ParseExact(finalList, "MM/dd/yyyy", CultureInfo.InvariantCulture)
priya AvanigaddaPosted Nov 12, 2014, 5:06 AM
.DAL:I'm using fr date format
var listSplit = DOB.Split('/'); string finalList = listSplit[1] + "/" + listSplit[0] + "/" + listSplit[2]; string datetime = DateTime.Now.ToString(finalList);
DateTime dateof = DateTime.Parse(finalList);
cmd.Parameters.Add("@DateofBirth", dateof);
In .cs I'm accesing this ....
I tried ur code also but im getting same error ..so cn any one tell me how to slve please??
Mariyappan sivathanuPosted Nov 12, 2014, 4:37 AM
Convert.ToDateTime(DateTime.Parse(txtBeginDT.Text.Trim())
instead of
DateTime.Parse(txt.text.Trim())
priya AvanigaddaPosted Nov 12, 2014, 3:52 AM
Joginder BangerPosted Nov 12, 2014, 2:24 AM
in your code, you can do the following:
or, if you'd like to specify the format of the date:
priya AvanigaddaPosted Nov 12, 2014, 2:21 AM
Zeeshan AzimPosted Nov 12, 2014, 2:11 AM
string Date2 = DateTime.Parse(datepicker.Text);
and keep your code in try catch blocks. Thanks