A user defines a date range, and submits it in one data type. I then need to create new thing in another data type for each week that the original date range falls in.
Ex:
Original date range
Weds Sept 18 2019 - Fri Sept 27 2019
Results in two new ranges:
Mon Sept 16 - Sun Sept 22 2019
Mon Sept 23 - Sun Sept 29 2019
Thinking I could use an API to achieve creating as many new things as weeks this but not sure how to go about it.
I think I can see a similar way of how to: take the start date of the range, convert that to a new range of the week that it falls in. I think, I can sort out the following weeks being generated later in the user journey once I have the first one.
I was trying to use the create new thing function, and take the weekFirstDay= startDate+(days): - startDateExtract:day-1 …but it wont let me add the subtract in front of the the last part or the -1 on the end…?
@louisadekoya Been experimenting adapting your reply to find the following Sunday into a workflow.
Not sure I’m doing it quite right tho because I can’t seem to make it work :s I assumed ‘moment’ was the current date/time, so I subbed that with the start date which I want to work from…
Happy to try to help but I’m not at a computer right now, so some of what I write below may not be in the exact syntax needed and you may have to check other examples to be sure.
First of all, make sure you are using moment.js, i.e did you add the momentJs script call to your page header as in my post?
Then to answer your question, yes ‘moment’ in the code I posted did refer to the current date in that example but you can pass a different date to moment and assign it to a variable.
This is where I’m unsure of the syntax without checking but something like:
var myDate = moment(“20190918”,“YYYYMMDD” );
You should replace the date with your dynamic date formated as YYYYMMDD.
Then in the code from my post (or in the code below which may be closer to what you need) , you should be able to replace ‘moment()’ with myDate.
var startOfWeek = moment().startOf('isoweek').toDate();
var endOfWeek = moment().endOf('isoweek').toDate();