1
votes

hi I have a case when i want to compare only date of datetime object. how can i achieve it without converting it to string.

public bool CheckSendEmailWithinCalendarDay(UnifiedUser user, string messageId, DateTime whenSent)
        {
            var result = _ctx.UserSpecificMessageHistories
                .Where(u => u.UserId == user.User.UserId)
                .Where(d => d.WhenSent.Date == whenSent.Date)
                .FirstOrDefault(m => m.EmailTemplate.Id == messageId);

            return Convert.ToBoolean(result);
        }
1
You are comparing only Date here: d.WhenSent.Date == whenSent.Date isn't it working ok? - Kamil Budziewski
Is the data from Entity Framework? - GrandMasterFlush
how it's not working, what's wrong? - Kamil Budziewski
"it is not workin(g)" - are you getting any error messages? If so, what do they say? - Damien_The_Unbeliever
no error, only breaks before continuing to return - John Dudley

1 Answers

3
votes

You can use

EntityFunctions.TruncateTime

or, if you're up to date (EF 6)

DbFunctions.TruncateTime

As you seem to be in linq to entities.