I'm trying to find a date x number of days after current date to filter a date but it doesn't take into account the number of days in the month.
For example if I add 5 days to today's date (31/03/2021) it shows 36/03/2021, please see code below and let me know where I'm going wrong please.
The code for this is on line > var formattedDate = (date.getDate()+30) + '/' + (date.getMonth()+1) + '/' + date.getFullYear(); <
Code: Select all
$j(function() {
var date = new Date();
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 5);
// formatted date .. change order and separator to the ones you selected in your AppGini project
// in the below line, the format is month/day/year
//Enddate = Begindate + timedelta(days=5)
var formattedDate = (date.getDate()+5) + '/' + (date.getMonth()+1) + '/' + date.getFullYear();
// now build the 4 parts of the filter
var filter = {
'FilterAnd[1]': 'and',
'FilterField[1]': 7, // change this to the actual index of your date field
'FilterOperator[1]': 'equal-to',
'FilterValue[1]': formattedDate
};
alert("formatted " + formattedDate + " Unformatted = " + date + "Future Date " + futureDate);
// building the filter url ... change tablename to the actual table name
var url = 'ported_view.php?' + $j.param(filter);
// finally, insert the filter button
$j('<a class="btn btn-lg btn-success" href="' + url + '"> Date Tester (Admin) </a>').prependTo('#top_buttons');
})