Help On String is not a Valid Date time

Posted by Vijayar under ASP.NET on 2/6/2012 | Points: 10 | Views : 1491 | Status : [Member] | Replies : 6
Hi
I am using Datetime to storein back end
In edit
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
string start1 = txtposteddate1.Text;
DateTime dtstart = DateTime.Parse(start1, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
string end1 = txtlastdate1.Text;
DateTime dtend = DateTime.Parse(end1, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
jBO.PostedDate = start1.ToString();

jBO.LastDate = end1.ToString();
But iam gettung the error as Help On String is not a Valid Date time
Where is the mistake
.The same works for insertion ,but for editing error appears where is the mistake

vijaya


Responses

Posted by: Swapnil on: 2/6/2012 [Member] Starter | Points: 25

Up
0
Down
From your code, following 2 lines may give you exception, if jBO.PostedDate or jBO.LastDate is date type because you are assigning string to date time. And why you are not using dtstart and dtend?

jBO.PostedDate = start1.ToString();
jBO.LastDate = end1.ToString();

Thanks and Regards,
Swapnil

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/6/2012 [Member] Starter | Points: 25

Up
0
Down
HI i am using as
jBO.Posteddate=dtstart.tostring();
jBO.Lastdate=dtend.tostring();
but getting the same error


vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 2/7/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

I think that this error generate the code the parse code. Please check your textbox date value, is it a valid date

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/7/2012 [Member] Starter | Points: 25

Up
0
Down
HI
I am selecting date by using calendar control,it is a valid date

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Swapnil on: 2/7/2012 [Member] Starter | Points: 25

Up
0
Down
replace

jBO.Posteddate=dtstart.tostring();

jBO.Lastdate=dtend.tostring();


with (remove .tostring())

jBO.Posteddate=dtstart;

jBO.Lastdate=dtend;


Thanks and Regards,
Swapnil

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/9/2012 [Member] Starter | Points: 25

Up
0
Down
HI
I am getting this error in this 3rd line of code.
IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
string start = txtposteddate.Text;


System.DateTime dtstart = DateTime.Parse(start, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response