Calculating and Passing Date Range for Dataset Filters
forOverview
When working with datasets in BDB Dashboard Designer, it's common to filter data based on date ranges — such as "Last 30 Days", "Last 7 Days", or "This Month".
In such scenarios, you need to dynamically calculate the start and end dates based on the current date, and then pass these values to the dataset for filtering.
This guide explains how to calculate and format the start date and end date based on a "Last 30 Days" selection.
Use Case: Filter for Last 30 Days
If a user selects "Last 30 Days" as the filter:
The End Date should be today’s date
The Start Date should be today minus 29 days
This ensures a full 30-day window (including today) has passed to the dataset.
Example Code
// Step 1: Get today's date
var todays_date = new Date();
// Example output: Thu Sep 25 2025 23:04:22 GMT+0530 (India Standard Time)
// Step 2: Format today's date as 'yyyy-mm-dd'
var formatted_end_date = $.datepicker.formatDate('yy-mm-dd', todays_date);
// Output: '2025-09-25'
// Step 3: Subtract 29 days from today's date to get the start date
todays_date.setDate(todays_date.getDate() - 29);
// Step 4: Format the calculated start date
var formatted_start_date = $.datepicker.formatDate('yy-mm-dd', todays_date);
// Output: '2025-08-27'Output Summary
Variable
Value (Example)
Description
formatted_end_date
2025-09-25
Today's date (end of range)
formatted_start_date
2025-08-27
29 days before today (start date)
How to Use it in the Dashboard?
You can now use formatted_start_date and formatted_end_date:
As input parameters for dataset filters
In the data connections to query external data sources
Within component scripts to control visualizations based on the date range
Best Practices
Recalculate dates dynamically each time the dashboard loads to ensure up-to-date filtering.
Store date logic in the Dashboard Script Area if reused across multiple components or datasets.
Use clear and meaningful variable names like ("startDate", "endDate", etc).
Last updated