Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Filtering on Date part of DateTime


I need to filter only events that starts today, ignoring the time of day. I have tried with the following extension method:

        public static FilterExpression AsDateMatch(this DateTime? value, DateTime matchValue)
            return new FilterExpression(x => x.Exists() & x.Value.Date.Match(matchValue));

...but this does not work. It seems that x.Value.Date.Match(matchValue) are not allowed.

I use the extension method like this:

.Filter(x => x.StartDate.AsDateMatch(DateTime.Now.Date))
Mar 03, 2016 13:19
            .Filter(x => x.StartDate.MatchDay(DateTime.Today.Year,
Mar 03, 2016 14:20

Great, but x.StartDate is nullable (i.e. of type DateTime?) and MatchDay() is only available for the non-nullable DateTime.

If anyone could explain why the code in my first post does not work, it would make me really happy! :-)

Edited, Mar 03, 2016 14:29
Mar 03, 2016 14:35

No it does not, and I can't understand why.

Mar 03, 2016 15:07

It seems that epifind cannot handle .Value

Can you try the following code:

public static FilterExpression<DateTime?> AsDateMatch(this DateTime? value, DateTime matchValue)
    var minValue = new DateTime(matchValue.Year, matchValue.Month, matchValue.Day, 0, 0, 0);
    var maxValue = new DateTime(matchValue.Year, matchValue.Month, matchValue.Day, 23, 59, 59);

    return new FilterExpression<DateTime?>(x => x.Exists() & x.InRange(minValue, maxValue));
Edited, Mar 03, 2016 15:31

Ok, I think I know why the original code doesn't work.

First, I've indexed the following object:

public class Event
    public string Title { get; set; }
    public DateTime? StartDate { get; set; }

Then I opened epifind index, and noticed that StartDate field is indexed as StartDate$$date

Then I used Fiddler to see all requests that are sent to epifind, and noticed that x.Value.Date.Match(matchValue) generates the following query:


Since StartDate.Value$$date field doesn't exist, we're getting no hits.

Hope this helps!

Edited, Mar 03, 2016 15:48

Thanks! :-)

Mar 08, 2016 7:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.