Comparing dates in a function

I have tried several solutions to check if the update record read is more than a week old, but the function script that runs on the database record fails. I have also tried to use .toJSON() , but no success. What can be wrong?

Hi Harald!
For manipulating dates it is better to use the Moment.js library (Moment.js | Docs).

You can try to do this instead:

let now = moment()
let pre = now.subtract(7, 'days');

if(moment(updatedCreatedDate).isBefore(pre){
    return 3
}

Thank you, now it works perfectly!

1 Like