ASP.NET - time issue in date - Asked By prasanth on 15-Jun-12 12:41 AM


i'm using this code for date chking. the problem is tht if update button is clicked the date and time is getting displayed and if i change the time error is coming as failed to convert datetime to int. Please help



protected
void Txtdoj_TextChanged(object sender, EventArgs e)


{



if ((Txtdob.Text != "") && (Txtdoj.Text != ""))


{



DateTime dt1 = Convert.ToDateTime(Txtdob.Text).Date;



DateTime dt2 = Convert.ToDateTime(Txtdoj.Text).Date;




int result = DateTime.Compare(dt1, dt2);



string srtvalue;



DateTime dt3 = System.DateTime.Now.Date;



int res = DateTime.Compare(dt1, dt3);



int resl = DateTime.Compare(dt2, dt3);





if (dt1==dt3 || dt2==dt3)


{

lbmsg.Text =

"both dates should be less than current date ";


}


else


{


if (result > 0)


{


// srtvalue = "is earlier than";


lbmsg.Text =

"DOB must be less than DOJ";


Txtdob.Focus();

Txtdob.Text =

"";


Txtdoj.Text =

"";


}


else if (result == 0)


{

lbmsg.Text =

"DOJ should be > than DOB";


}


else if ((res < 0) || (resl < 0))


{


}


else


{


//srtvalue = "is later than";


lbmsg.Text =

"";


}

}

}


else


{

lbdob.Visible =

true;


lbdob.Text =

"Enter date of birth";


}

}

Jitendra Faye replied to prasanth on 15-Jun-12 12:42 AM
I think you want to get only date.

Then use this code-

string date = DateTime.Now.ToShortDateString();   


Try this and let me know
prasanth replied to Jitendra Faye on 15-Jun-12 12:44 AM
not working i tried it
TSN ... replied to prasanth on 15-Jun-12 01:18 AM
hi...

please provide the code where you are getting the error date time to int ..
if its in the update button clcik event then provide that code

Chintan Vaghela replied to prasanth on 15-Jun-12 01:32 AM
Enter your texbox Date in mm/dd/yyyyy fromat

check it and let me know