I have an insert in entity framework as follows
Contacto a = this.ToEntity();
contexto.Contactos.Add(a);
a.FechaAlta = DateTime.Today.Date;
a.Icono = "red.png";
DateTime hoy = DateTime.Today.Date;
a.Oculto = false;
a.FechaContacto = hoy;
contexto.SaveChanges();
return true;
The issue is that it always saves dates in the form 2019-04-04 00:00:00.000 and it does not save the time, and I need it, I have the field declared like this:
public DateTime? FechaContacto { get; set; }
Does anyone know what happens? both in DateAdded and in DateContact it does not save the time... thanks
To persist the date and time you should use
in this way you will have both data
By using the
Date
you are only taking the date leaving the time with a standard valueDateTime.Now Property