Skip to main content
All CollectionsGetting Started
How to Use the JavaScript Column in Glide to Check If a Date Falls Within a Range
How to Use the JavaScript Column in Glide to Check If a Date Falls Within a Range
Updated this week

Glide is a powerful no-code platform that allows users to build apps with ease. However, some advanced logic—like determining if a date falls within a specific range—requires the use of the JavaScript column. In this article, we will guide you through setting up this logic in Glide, including column configurations and the necessary JavaScript code.

Setting Up the Columns

To achieve this, we need the following columns:

  1. Initial Date Column – A date column where users input the date they want to check.

  2. Start Date Column – A date column representing the beginning of the date range.

  3. End Date Column – A date column representing the end of the date range.

Formatting the Date Columns

Glide's date columns provide timestamps that are too long for the JavaScript column to process efficiently. To avoid infinite loading, we must create three "Format Date" columns for each of our date columns (Initial Date, Start Date, and End Date). Set the format for these columns to yyyy/MM/dd.

  1. Formatted Initial Date Column

  2. Formatted Start Date Column

  3. Formatted End Date Column

Creating the JavaScript Columns

1. JavaScript Column for Displaying the Range

To make sure our JavaScript can process the start and end dates correctly, we create a JavaScript column that combines them into a single value.

Code:

return `${p1},${p2}`;
  • p1 = Formatted Start Date Column

  • p2 = Formatted End Date Column

This column will return a string like: 2024/10/13,2024/10/23.

2. JavaScript Column for Date Comparison

Now, we need another JavaScript column that checks whether the Formatted Initial Date falls within the Formatted Start Date and Formatted End Date.

Code:

const [startDate, endDate] = p2.split(","); // Split p2 into start and end date const targetDate = new Date(p1); // Parse p1 as a date const start = new Date(startDate); // Parse startDate as a date const end = new Date(endDate); // Parse endDate as a date // Check if p1 is between start and end dates return targetDate >= start && targetDate <= end;
  • p1 = Formatted Initial Date Column

  • p2 = Result of the first JavaScript column (which contains Start and End dates)

This column will return true if the date falls within the range, and false otherwise.

Testing the Setup

If you’d like to see this setup in action, we have created a Glide template demonstrating how it works. You can access the template here and review the settings in Data Editor > JavaScript Table.

Conclusion

By following these steps, you can efficiently use JavaScript in Glide to check if a date falls within a given range. This method ensures compatibility and prevents performance issues caused by Glide's default date formatting.

Let me know if you have any questions!

Did this answer your question?