Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
tb_DateFrom.Text = dateIndv.dateFrom;

//error is cannot convert System.DateTime to string
Posted
Updated 30-Jan-14 20:36pm
v3

What i can see is ..you are converting type datetime to string that's why you are getting the error
you have to first convert datetime to string then pass the value
Try this
tb_DateFrom.Text = dateIndv.dateFrom.tostring("dd-MMM-yyyy");
 
Share this answer
 
call the ToString() method of the DateTime variable:
tb_DateFrom.Text = dateIndv.dateFrom.ToString();
 
Share this answer
 
Try like this
C#
DateTime dt = DateTime.ParseExact(dateString, "ddMMyyyy", 
                                  CultureInfo.InvariantCulture);
               dt.ToString("yyyyMMdd");

Refer:http://stackoverflow.com/questions/3477735/convert-datetime-to-string-formatyyyymmdd[^]
This may help.
 
Share this answer
 
How can you assign a data type to another unless you dont convert it or unless they are not related(or rather cast it to that type). Why can i convert an int to byte? or vice versa?.

Why do i not have ToByte() for every type or can i? or can i not? Why do i have ToString()?

By using ToString() i am converting the DateTime to string format.
If you notice one thing you will find you can call the ToString() on any type. But have you wondered why?

Read the basics of object class. In future you will never ask this doubt my friend. Please dont mind. Just google the stuff brother.

My aim here is not to insult you. I just want that you start learning.

Thanks brother,
Happy Learning.
 
Share this answer
 
Just add ToString() for conversion

C#
tb_DateFrom.Text = dateIndv.dateFrom.ToString();
 
Share this answer
 
change your code from:-
tb_DateFrom.Text = dateIndv.dateFrom;

to
tb_DateFrom.Text = dateIndv.dateFrom.ToString();
 
Share this answer
 

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