Google Trends Parser - Custom Time Range

Discussion in 'A-Parser Support Forum' started by scrapefun, Apr 26, 2023.

  1. scrapefun

    scrapefun A-Parser Enterprise License
    A-Parser Enterprise

    Joined:
    Feb 24, 2015
    Messages:
    184
    Likes Received:
    34
    Is there a way to make a macro that will set a date range for the past 8 days that I can use in the "custom time range" field in the Google Trends parser?

    Currently, I have to update manually every day which is a pain so would be great to automate if possible.
     
  2. Support

    Support Administrator
    Staff Member A-Parser Enterprise

    Joined:
    Mar 16, 2012
    Messages:
    4,545
    Likes Received:
    2,163
    This can be done with a small script and tools.js.
    Code:
    Tools.prototype.getDateRange = function(days) {
        let d = new Date();
        const end = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).substr(-2) + '-' + ('0' + d.getDate()).substr(-2);
        d.setDate(d.getDate() - days);
        const start = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).substr(-2) + '-' + ('0' + d.getDate()).substr(-2);
        return `${start} ${end}`;
    }
    [​IMG]
     
    scrapefun likes this.
  3. scrapefun

    scrapefun A-Parser Enterprise License
    A-Parser Enterprise

    Joined:
    Feb 24, 2015
    Messages:
    184
    Likes Received:
    34
    Thanks! This works great.
     
    Support likes this.

Share This Page