I have to return a datetime from a string in my asp.net project to feed a calendar that only accepts datetime. The string is a two-digit number that represents the expiration date of a product. I convert it with the following code to DateTime, but it shows an error that I understand, but I do not know how to solve it.
"Can not imply convert system.datetime to string"
I can not apply dt2.ToString (); Because the calendar plugin would not read it since it only accepts DateTime. Thank you!!
public IHttpActionResult GetPolizas()
{
var polizaDto = _context.Poliza
.Include(m => m.UsoVehiculo)
.Include(m => m.Compania)
.Include(m => m.MedioPago)
.Include(m => m.Cliente)
.ToList();
foreach (var poliza in polizaDto)
{
var fecha = poliza.Vencimiento;
fecha = DateTime.Now.Month + "-" + poliza.Vencimiento + "-" + DateTime.Now.Year + " "+ "00:00:00";
DateTime dt2 = DateTime.ParseExact(fecha,
"MM-dd-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
poliza.Vencimiento = dt2;
};
return Ok(polizaDto);
}