Find Future Date

Topics related to AppGini plugins/add-ons go here.
Post Reply
aduff
Posts: 23
Joined: 2020-10-24 15:01

Find Future Date

Post by aduff » 2021-03-08 17:02

Hi.
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');
	
})

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Find Future Date

Post by zibrahim » 2021-03-09 00:01

Hi Aduff,
Why don't you try to use "moment" function which is already included as one of AG resources.
You can check this site for detail.
https://momentjs.com
You can also refer to the previously discussed topic here
viewtopic.php?f=2&t=3531&hilit=harvest

I hope this will help.

Stay safe.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Find Future Date

Post by aduff » 2021-03-09 08:45

Thank you zibrahim.

I will look into your suggestions and try it over the next few days.

Kind Regards.

Post Reply