How can I search a DATE on Entity framework

  Kiến thức lập trình

Im trying to get a date on my database and I’ve try different things but nothing seems to work

This is my date on the dataBase “2024-04-18 19:47:36.337” its type datetime, im using Microsoft sql server and entityFramework on C# and the variable is public DateTime InitH { get; set; }

My query is more complex than this, but I found the problem is the date. So I try to get an optimal solution to search dates

public void obtenerFechaHarcodeada()
{
    DateTime fecha = new DateTime(2024, 4, 18, 19, 47, 36);


    var registro = _dbContext.AssignmentRecords
        .FirstOrDefault(r=> r.InitH == fecha);

}

Any Idea ?

im trying to save the same date and the same variable to search on the DB but it never works

New contributor

Wrench 8Bits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT