Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't convert DateTime to string

Tags:

c#

datetime

wpf

I'm trying to convert a DateTime to a string but actually the dt variable passed in the getFixtures method is underlined in red.

DateTime dt = DateTime.ParseExact(Calendar.SelectedDate.Value.ToString(), "ddMMyyyy",
                                  CultureInfo.InvariantCulture);
dt.ToString("ddMMyyyy");

fixtures.getFixtures(dt);

Error:

Can't convert DateTime to string.

What am I doing wrong?

like image 918
Harold Finch Avatar asked Dec 14 '22 12:12

Harold Finch


2 Answers

Seems you want pass a string to the getFixtures but actually you are passing the dt which is a DateTime.

dt.ToString("ddMMyyyy"); does not change the dt to string, so you should save it's output to a string and use that string. Here is the code:

var stringDt = dt.ToString("ddMMyyyy");

fixtures.getFixtures(stringDt );
like image 171
Hossein Narimani Rad Avatar answered Dec 30 '22 23:12

Hossein Narimani Rad


Your code:

dt.ToString("ddMMyyyy");
fixtures.getFixtures(dt);

If you want to pass string representation of datetime inside a method, change it to :

fixtures.getFixtures(dt.ToString("ddMMyyyy"));
like image 40
Fabjan Avatar answered Dec 30 '22 22:12

Fabjan