Skip to content

Instantly share code, notes, and snippets.

@Qubadi
Created February 2, 2024 09:25
Show Gist options
  • Save Qubadi/f227378730bf7c62843d869d87513efc to your computer and use it in GitHub Desktop.
Save Qubadi/f227378730bf7c62843d869d87513efc to your computer and use it in GitHub Desktop.
Jetsmartfilters Date range: custom JavaScript code for JetSmartFilters Date Range Picker that automatically sets today's and tomorrow's dates.
We have developed a custom JavaScript code for JetSmartFilters Date Range Picker that automatically sets today's and tomorrow's dates.
Copy the code and paste in to your snippet plugins ( JS snippet )
Note: Monthnames can be changed to your language.
// Function to format date to 'F j, Y'
function formatDate(date) {
var d = new Date(date),
monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"],
day = '' + d.getDate(),
year = d.getFullYear();
return monthNames[d.getMonth()] + ' ' + day + ', ' + year;
}
// Function to set the date in the date input fields
function setDates() {
var today = new Date();
var tomorrow = new Date(today);
// Set tomorrow's date
tomorrow.setDate(tomorrow.getDate() + 1);
// Format dates
var todayFormatted = formatDate(today);
var tomorrowFormatted = formatDate(tomorrow);
// Set today's date in the 'from' input and tomorrow's date in the 'to' input
document.querySelector('.jet-date-range__from').value = todayFormatted;
document.querySelector('.jet-date-range__to').value = tomorrowFormatted;
}
// Call the function when the window loads
window.onload = setDates;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment