I have the problem, that I only need the date when filling the database. How can I convert the DateTime, that I get only the date out.

CodePudding user response:
Depending on your database, there are several data types for storing dates and times. You are using one that supports both (date and time). I think it's "datetime" or "timestamp". But you need to use a type that stores only the date.
In the data model class of your application, you must specify the type for the field - "DATE".
You can use one of methods:
// In model class
[Column(TypeName = "DATE")]
public virtual DateTime DestinationDate {get; set;}
// In model settings
this.modelBuilder.Entity<BusinessTripDocument>(document =>
{
document.Property(d => d.DestinationDate).HasColumnType("DATE");
}
After applying the changes, you will need to make a migration to the database.
