Compare dates in filter

Comments

4 comments

  • Daniel P
    Engaged

    Courtney Jordan Is there a way to compare two dates (a last updated date and the current date/time for example) and get a difference in minutes in a filter? Much like the dateAdd in handlebars but for a filter?

    1
  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Chris Hunter,

    Sorry for the delay on this. We are looking into it to determine if this is an issue we need to fix. Will hopefully have this info by tomorrow. Thanks so much for letting us know that you've run into this issue, and please continue to let us know what else we can do to improve your experience!

    0
  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Chris Hunter,

    First, set your data type to Expression if you haven't already. To do so, click the gear icon next to the last field (hover to the right of the field to display it). 

    Then, set your filters like this:

    record.lastExportDateTime is less-than ["epochtime", "2021-09-07T00:00:000Z"]

    Please let us know if that works for you! Thanks!

    0
  • Tom Santiago Principal Technical Writer Community moderator
    Engaged
    Top Contributor
    Celigo University Level 4: Legendary

    Hi Daniel P,

    Filter syntax via the filter editor is very limited and uses a cumbersome syntax:

    https://docs.celigo.com/hc/en-us/articles/360025927811-Apply-filters#Supportedexpressions

    Orion Abrams (one of our Senior Engineers), suggested you instead use a preSave page hook and use something like this to get what I think you are looking for:

    function preSavePageFunction(options) {
        const records = options.data;
        for (let i = records.length - 1; i >= 0; i--) {
            let dataRec = records[i];
            //add date comparison here
            if (dataRec.dateModifiedByUser) {
                let date1 = new Date(options.lastExportDateTime);
                let date2 = new Date(dataRec.dateModifiedByUser);
                if (date2.getTime() < date1.getTime()) {
                    options.data.splice(i, 1);
                }
            }
        }
        return {
            data: options.data,
            errors: options.errors
        }
    }
    0

Please sign in to leave a comment.