@Rock Hitman , you could try the following code to use linq to check if the datetime is within 24 hours.
DataTable table=new DataTable();
table.Columns.Add("Id",typeof(int));
table.Columns.Add("CreationDate", typeof(DateTime));
table.Rows.Add(123,DateTime.Parse("2021-12-24 10:00 AM"));
table.Rows.Add(456,DateTime.Parse("2021-12-22 9:00 AM"));
table.Rows.Add(789, DateTime.Parse("2021-12-20 8:00 AM"));
int passedId = 123;
DateTime now = DateTime.Now;
DateTime yesterday = now.AddDays(-1);
var result = (from t in table.AsEnumerable()
where t.Field<int>("Id")==passedId
select (t.Field<DateTime>("CreationDate")>yesterday&&t.Field<DateTime>("CreationDate")<=now)).FirstOrDefault();
I used datatable to replace your table in the database.
Result:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.