Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
app script add loop by timestamp adding 30 days for every loop

I have script code in app script this script return data from API as JSON.

input API has two parameter: first & second. these parameter is timestamp.

first is timestamp & second is timestamp.

API just take 30 days between first date and second, if add 31 not working.

This is my code:

function script() {
    // Current date.
  const current_date = new Date()//.valueOf();
  Logger.log(current_date)

  var timestamp = Number(current_date).toFixed(0);
  Logger.log(timestamp)

  // manual date
  const inputdate = new Date('01, 17, 2022')//.valueOf();
  Logger.log(inputdate)
  var timestampp = Number(inputdate).toFixed(0);
  Logger.log(timestampp)

  // this add 30 days in inputdate
  var newdate = inputdate.setDate(inputdate.getDate()+30); 
  // Convert Date To Timstamp
  var timestamp2 = Number(newdate).toFixed(0);
  Logger.log(timestamp2)

  // I want to use loop by change date for every loop add 30 days and stooped if date = current_date

  const data = [] // push arrays from obj return json

  const host = "****"
  const res = UrlFetchApp.fetch(host + "?first="+ timestampp +"&second="+timestamp2);
  const obj = JSON.parse(res); // To JSON
  Logger.log(obj);
  
}

Example:

first loop: use "?first="+ 01, 17, 2022 +"&second="+ 02, 16, 2022

second loop use: "?first="+ 02, 17, 2022 +"&second="+ 03, 19, 2022

Third loop use: "?first="+ 03, 20, 2022 +"&second="+04, 19, 2022

and keep loop run get json obj and adding it in data array.

stop loop if last date > current_date.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!