Creating time periods from two dates for a list of objects
Options
![Tom Cvij](https://us.v-cdn.net/6037124/user_avatars/2167719.jpg)
Tom Cvij
Member ✭
Hey folks, really exciting getting going with Xano, looks great so far. I'm having a bit of a trouble getting something over the line in workflows which id massively appreciate some advice on. An example of what I want to achieve is:
Data Table 1
Item 1 Start 01/05/21 End 06/15/21
Item 2 Start 03/20/21 End 09/24/21
Create a new data table 2:
Item 1 Start 01/05/21 End 01/31/21
Item 1 Start 02/1/21 End 02/28/21
Item 1 Start 03/1/21 End 03/31/21
Item 1 Start 04/1/21 End 04/30/21
Item 1 Start 05/1/21 End 05/31/21
Item 1 Start 06/1/21 End 06/15/21
Item 2 Start 03/20/21 End 03/31/21
Item 2 Start 04/1/21 End 04/30/21
Item 2 Start 05/1/21 End 05/31/21
Item 2 Start 06/1/21 End 06/30/21
Item 2 Start 07/1/21 End 07/31/21
Item 2 Start 08/1/21 End 08/31/21
Item 2 Start 09/1/21 End 09/24/21
In reality there will be associated values that will also need to be calculated based upon these time periods, but I can hopefully deal with that as a step 2.
What I've managed to do is create the first and second item, in that I take the start date, use last day of month function, and then + 1 day to get me the start of the next period.
What I'm struggling with is how to structure it in such a way that I get the required output.
I understand I need to loop through to create all required entries.
I believe "Item 1", "Start", "End" I need to define as keys?
Would I need to loop through the "Add Record" function to add each row in turn into the database?
Data Table 1
Item 1 Start 01/05/21 End 06/15/21
Item 2 Start 03/20/21 End 09/24/21
Create a new data table 2:
Item 1 Start 01/05/21 End 01/31/21
Item 1 Start 02/1/21 End 02/28/21
Item 1 Start 03/1/21 End 03/31/21
Item 1 Start 04/1/21 End 04/30/21
Item 1 Start 05/1/21 End 05/31/21
Item 1 Start 06/1/21 End 06/15/21
Item 2 Start 03/20/21 End 03/31/21
Item 2 Start 04/1/21 End 04/30/21
Item 2 Start 05/1/21 End 05/31/21
Item 2 Start 06/1/21 End 06/30/21
Item 2 Start 07/1/21 End 07/31/21
Item 2 Start 08/1/21 End 08/31/21
Item 2 Start 09/1/21 End 09/24/21
In reality there will be associated values that will also need to be calculated based upon these time periods, but I can hopefully deal with that as a step 2.
What I've managed to do is create the first and second item, in that I take the start date, use last day of month function, and then + 1 day to get me the start of the next period.
What I'm struggling with is how to structure it in such a way that I get the required output.
I understand I need to loop through to create all required entries.
I believe "Item 1", "Start", "End" I need to define as keys?
Would I need to loop through the "Add Record" function to add each row in turn into the database?
Comments
-
Once you've created the list of all your items, you then would for a For Each Loop through that list, which will produce a variable For Each item... place the Add Record nested under that and reference the For Each variable in the Add Record function... a good example of that logic in action is this tutorial of adding a list of items from an external API:
-
Thanks Michael, that's useful guidance! I'm unfortunately having issues creating all variables in the first place, as the number of variables will depend on the time between the two dates. I need to loop through and create X values based on a condition. Take previous value + 1 month while this variable is less than the end date. The "While Loop" wont let me reference the variable that I am creating, what am I missing?
-
Here is where I got to:
-I bring in my start and end dates as variables.
-Create a new array
-Add my Start date to that array
-Then trying to loop through my array taking the last value and using "first day of next month" as a new array value, only when the last array value is < the End date.
This should give me a list of month start dates, however I am getting and error with "Potential infinite loop. Please limit your loop operations to under 100. ".
Is this because I am using the last item in the array as the basis for adding to the array as well as the condition with which to run the loop?
[image.png]
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback