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?
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 );
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With