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.