1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Join our Telegram chat: https://t.me/a_parser_en
    Dismiss Notice

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:
    174
    Likes Received:
    30
    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,377
    Likes Received:
    2,107
    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:
    174
    Likes Received:
    30
    Thanks! This works great.
     
    Support likes this.

Share This Page