cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Increasing every hours in each iteration using for loop in thingworx.

Hrishabh.Sharma
10-Marble

Increasing every hours in each iteration using for loop in thingworx.

var date = new Date();

for (let index = 0; index < 12; index++) {
    let startDate = new Date(date);
    startDate.setHours(18 + index, 0, 0);
   
    let endDate = new Date(date);
    endDate.setHours(18 + index + 1, 0, 0);
   
    console.log("StartDate " + startDate);
    console.log("EndDate " + endDate);
}
ACCEPTED SOLUTION

Accepted Solutions

Hi @Hrishabh.Sharma 

 

You can use below script to increase startime & endtime by 1 hour  

let startTime = new Date();
// End Time plus 1 hour from startTime
let endTime = dateAddHours(startTime, 1);

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(TestDS1)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "TestDS1"
});

// Iterate
let i = 0;
while (i < 5) {
	/* 
	LOGICS
	*/
	result.AddRow({
		"StartDate": startTime,
		"EndDate": endTime
	});
	// StartTime & EndTime will increase at end of iteration
	startTime = endTime;
	endTime = dateAddHours(startTime, 1);
	i++;
}

 

Output :

Velkumar_0-1721626503641.png

/VR

 

View solution in original post

3 REPLIES 3

Hi @Hrishabh.Sharma ,

If you observe any the vast majority of the requests for help in this forum, you will observe that they follow a specific structure, where the user explains what they want to do and what the issue is.

Would you be able to explain what are you trying to achieve and where exactly you encountered issues?

I observed you posted just the code in the section where you should explain these things I mentioned above, and also the title does not clarify these as well.

 

Hi @VladimirRosu,

Most of things, i have posted just for future reference to itself and others, I am not asking to anybody for answers.

Hi @Hrishabh.Sharma 

 

You can use below script to increase startime & endtime by 1 hour  

let startTime = new Date();
// End Time plus 1 hour from startTime
let endTime = dateAddHours(startTime, 1);

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(TestDS1)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "TestDS1"
});

// Iterate
let i = 0;
while (i < 5) {
	/* 
	LOGICS
	*/
	result.AddRow({
		"StartDate": startTime,
		"EndDate": endTime
	});
	// StartTime & EndTime will increase at end of iteration
	startTime = endTime;
	endTime = dateAddHours(startTime, 1);
	i++;
}

 

Output :

Velkumar_0-1721626503641.png

/VR

 

Announcements

Top Tags