Using moment js in Data View Filter

I have a date view that looks like this:

<dmx-data-view id="dv_completed_today" dmx-bind:data="sc_getTasks.data.api1.data.List" filter="moment(mx_Custom_46).isSame(moment(), 'day')"></dmx-data-view>

mx_Custom_46 is a field which exists on the data and has a format like “2020-10-02 15:52:00” . However this query doesn’t work. There is an object in the data which satisfies this value, but it is not getting filtered. The result shows zero entries.

How can I make this work?

You need to use App Connect expressions and formatters in the filter property. So just try using the data binding picker and data formatter. There are a lot of date formatting and conversation functions there.

Thanks George, actually < and > works really well for comparing dates. But it seems there’s no formatter to compare two dates to be equal.

However, your comment gave me some direction and I was able to make a custom formatter for that using: Creating Custom Formatters (PHP and client-side) post and use the custom formatter in the data view filter to achieve the result :slight_smile:

dmx.Formatter('string', 'isSameDate', function (val, other_date) {
    return moment(val).isSame(other_date, 'day')
});
1 Like

Comparing two dates to be on an equal date is actually very easy. You format them both to date only string like yyyy-mm-dd and then you compare those two strings

1 Like