Calculate date difference and compare with integer field in lambda expression

2

I have a date field (DateTime) and also a field of type integer. I need to make the difference between this date field and today's date (DateTime.Now) and compare if it is larger or smaller than my integer field. I made and gives this error.

Oprerator '>' cannot be applied to operands of type 'System.TimeSpan' and 'int'

This is my expression:

var atendimento = db.T_CRM_StatusPDV
                              .Where(dt => (dt.DT_TransacaoV - DateTime.Now) > dt.DE_FrequenciaTrans)
    
asked by anonymous 05.06.2014 / 21:03

1 answer

2

The days part of TimeSpan is missing:

var atendimento = db.T_CRM_StatusPDV
                  .Where(dt => ((TimeSpan)(dt.DT_TransacaoV - DateTime.Now)).Days > dt.DE_FrequenciaTrans)

Reference: link

If the number of days allows a fractional part, try TotalDays :

var atendimento = db.T_CRM_StatusPDV
                  .Where(dt => ((TimeSpan)(dt.DT_TransacaoV - DateTime.Now)).TotalDays > dt.DE_FrequenciaTrans)
    
05.06.2014 / 21:12