Hi,
On running my project at the first time in Visual Studio 2012 all the values I have entered will be inserted to database and the save process will be success. But after first run I could not run the same code, it shows an error message "String was not recognized as a valid DateTime".
Please help me
Loading


Renjith V SRank #5,293 · 304 reputationPosted May 13, 2014, 8:30 PM EDT
Abhay ShankerRank #375 · 6.7K reputationPosted May 13, 2014, 8:43 PM EDT
Anupam SinghRank #643 · 3.7K reputationPosted May 13, 2014, 8:49 PM EDT
It may be because of Globalization .Because I have faced the same issue a long time back that I was using different culture(settings).
Renjith V SRank #5,293 · 304 reputationPosted May 13, 2014, 8:52 PM EDT
Can you please explain the solution. If I use nearby date of today the error will be occured otherwise its fine.
Anupam SinghRank #643 · 3.7K reputationPosted May 13, 2014, 8:58 PM EDT
Renjith V SRank #5,293 · 304 reputationPosted May 13, 2014, 9:02 PM EDT
In my project I have used a parameter as string AddedDate and I am using a table details, this table include AddedDate and other columns. I am using JSON to pass the value entered in the text box AddedDate and it will be stored in the SQL database as well. But when ever I tried today's date or 2 days before today, it will show the described error.
Renjith V SRank #5,293 · 304 reputationPosted May 13, 2014, 9:08 PM EDT
I am saving this time in my table details column name AddedDate and it is declared as datetime. In my project I am using JSON to pass the values. In my aspx page I declared variable using JSON and in aspx.cs page I have used parameter string AddedDate and the value will be get as
"objInfoBO.AddedDate = Convert.ToDateTime(AddedDate); ".
Abhay ShankerRank #375 · 6.7K reputationPosted May 13, 2014, 11:08 PM EDT
Not sure, but check with this. DateTime date = DateTime.ParseExact(this.Text, AddedDate, CultureInfo.InvariantCulture);objInfoBO.AddedDate = date ;
Also check date format in string
Renjith V SRank #5,293 · 304 reputationPosted May 14, 2014, 3:14 AM EDT
Its the problem of date format in some function it is mm/dd/yyyy format and in somewhere its in dd/mm/yyyy format. I need to change the format to same for all places.
Anupam SinghRank #643 · 3.7K reputationPosted May 14, 2014, 3:25 AM EDT
Seems time is not being consider.
go to the article here
written by mahesh sir. and I am sure you wont need more help in this.
Renjith V SRank #5,293 · 304 reputationPosted May 14, 2014, 4:22 AM EDT
I have got the solution for my problem. Its the date picker date format problem. I have used a date picker plugin for adding calender in the text box. Its default format is MM/dd/yyyy. But I need to pass the date in the dd/MM/yyyy format. So I need to change the format there by using the below code.
$("#txtAddedDate").datepicker({dateformat : "dd/mm/yyyy"});
Thanks for the Support Anupam.
Anupam SinghRank #643 · 3.7K reputationPosted May 14, 2014, 4:38 AM EDT