cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript for loop using date as counter

SOLVED
mcbane
New Contributor

Javascript for loop using date as counter

Hi. I'm trying to create a for loop using a date starting with 1/1/2021 and going to today's date as below:

 

for(var d = aqDateTime.SetDateElements(2021, 01, 01); d <= aqDateTime.Now(); aqDateTime.AddDays(d, 1))
{

...

}

 

The var d is not incrementing by 1 day each time. It's staying constant at 01/01/2021. Can someone point me in the right direction? I had it working when I was using a javascript date object, but that creating other hurdles inside the for loop. I really want to use a DateTime (or Date) in TestComplete's native date format. Thanks!

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: Javascript for loop using date as counter

Hi,

 

 It's staying constant at 01/01/2021.

It stays constant because you do not change it.

Try this:

for(var d = aqDateTime.SetDateElements(2021, 01, 01); d <= aqDateTime.Now(); d = aqDateTime.AddDays(d, 1))

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

3 REPLIES 3
AlexKaras
Community Hero

Re: Javascript for loop using date as counter

Hi,

 

 It's staying constant at 01/01/2021.

It stays constant because you do not change it.

Try this:

for(var d = aqDateTime.SetDateElements(2021, 01, 01); d <= aqDateTime.Now(); d = aqDateTime.AddDays(d, 1))

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

sonya_m
Community Manager

Re: Javascript for loop using date as counter

Thank you for sharing this idea, Alex!

 

@mcbane does this help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
mcbane
New Contributor

Re: Javascript for loop using date as counter

Thank you. I really do appreciate the response. I had actually bulled my way through the javascript object method. I did plug this in real quick to my aqConvert version of the function, and yes, it works.

 

Thank you so much.

 

Tommy

New Here?
Join us and watch the welcome video:
Announcements