Compare dates in scripting app

Hi, everyone!

I need your help: I have installed the scripting app, and I am trying to make a report going through all the records in one of my tables.

I would like to be able to compare the date in one of the columns (type Last Modified Time) with the current date (today), because I only want to output records that are 2 days old or less.

I’ve tried some scripts I’ve seen around here (if (DATETIME_DIFF (TODAY (), {theDate}, ‘d’)> 2)), but they don’t work for me.

Thank you.

Welcome to the Airtable community!

The code you’ve see (if (DATETIME_DIFF (TODAY (), {theDate}, 'd')> 2) looks like code for a formula field, not code for Scripting app. Formula fields use an Airtable specific language. Scripting App uses JavaScript.

If you want compare dates in Scripting app, you should convert the date strings from getCellValue to JavaScript date objects. Then you can use the getTime() method on the date objects, and finally do the arithmetic with those values.

1 Like

Thanks a lot, @kuovonne!!

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.