Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My code as follows

DateTime selecteddate = Txtfromdate.SelectedDateValue.ToString();
if (selecteddate.DayOfWeek != DayOfWeek.Monday)
{
lblmsg.Text = "Yo must select the monday date only";
return;
}


wheni execute the above code shows error as follows

Cannot implicitly convert type 'string' to 'System.DateTime'

The above error shows in below line as follows
DateTime selecteddate = Txtfromdate.SelectedDateValue.ToString();

please help me.
Posted

Well, than don't try to assing a string to a datetime variable! What's wrong with something like this:

C#
if (Txtfromdate.SelectedDateValue.DayOfWeek != DayOfWeek.Monday)
{
lblmsg.Text = "Yo must select the monday date only";
return;
}


Assuming that SelectedDateValue field is of type DateTime, since it is not clear what kind of object Txtfromdate is.
 
Share this answer
 
Dont use ToString(), Use

Txtfromdate.SelectedDate.ToShortDateString()
 
Share this answer
 
Comments
Gihan Liyanage 15-Sep-14 6:23am    
Did you got a solution from my support, I can see you have not accepted any answer.If you are ok with this answer plz accept it. Then any user having same problem can identified it has solved the problem..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900