I am trying to retrieve records based on a specific date field. My criteria is to only show records whose values do not fall within current month or greater than today's date.

I already coded a criteria that is working for getting records with future dates. Could someone please assist me on how to solve the problem with showing records that are not in current month.

Thank you very much!

var criteria = Session.CreateCriteria<GLEntry>();
criteria.Add(Expression.Gt("EffectiveDate", DateTime.Today));
有帮助吗?

解决方案

Just need to to a less than with the first day of the current month.

var firstOfMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
criteria.Add(Expression.Lt("EffectiveDate", firstOfMonth));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top