I am trying to convert dateTime into string format such as dd-MM-yy,but while trying to convert into string format i have get an compile time error.
public List<ExpertTrckerReportTO> SetFeatureEventDetails(DateTime d1, DateTime currentDate, string eventName, List<ExpertTrckerReportTO> lst)
{
ExpertTrckerReportTO _expertTrckerReportTO = new ExpertTrckerReportTO();
_expertTrckerReportTO.DaysUntilFutureEvent = (d1 - currentDate).Days;
_expertTrckerReportTO.FutureEventName = eventName;
string format = "dd-MM-yy";
_expertTrckerReportTO.FutureEventDate = d1.ToString(format,CultureInfo.InvariantCulture);
lst.Add(_expertTrckerReportTO);
return lst;
}
the below line through the error
_expertTrckerReportTO.FutureEventDate = d1.ToString(format,CultureInfo.InvariantCulture);
Can any one help me me with the syntax how to solve the error.
That happend because _expertTrckerReportTO.FutureEventDate
is DateTime. You cannot implicitly convert d1.ToString(format,CultureInfo.InvariantCulture);
(string) to DateTime
May be you want
_expertTrckerReportTO.FutureEventDate = d1
Sorry. Post as answer because I haven't enough raiting to comment
Try
DateTime.ToString();
Hope It's the solution you hoped :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.