How do you compare the date values using predicate group
this is what I have been trying to do
var predicateGroup = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };
predicateGroup.Predicates.Add(Predicates.Field<Contents>(f => f.Guid, Operator.Eq, staticContents.Guid));
predicateGroup.Predicates.Add(Predicates.Field<Contents>(f => f.StartDate, Operator.Ge, DateTime.UtcNow));
predicateGroup.Predicates.Add(Predicates.Field<Contents>(f => f.EndDate, Operator.Le, DateTime.Now));
I am trying to pick the value with a specific GUID and the want it to lie between the required startdate and enddate.
I tried the BetweenValue as well but it dosent seem to help.
Comparing dates:
Instead of doing:
predicateGroup.Predicates.Add(Predicates.Field<Contents>(f => f.EndDate, Operator.Le, DateTime.Now));
You may also compare on the ISO8601 string representation of the date. "2015-12-31". Like this:
predicateGroup.Predicates.Add(Predicates.Field<Contents>(f => f.EndDate, Operator.Le, "2015-12-31"));
Read more about Query comparing dates in SQL in another Stack overflow post. This post also links to an MSDN page explaining how to format culture invariant string formats for dates and also date-times if that may be your issue.
Also remember that the argument Operator.Ge by default will render ">=", while Operator.Gt by default renders ">" if that could be the case. The same goes for Operator.Le/Operator.Lt. (This is probably not the issue here since .Gt and .Lt will shrink your 'between' interval)