Course date + 7, 14 or 21 days

We are busy converting our course administration with Wappler. This goes well except for 1 point. We would like to automatically schedule all our course days.
It’s about the following.
For example, a course starts on 06-05-2019 with a course part on the same day for 10 weeks. For the course parts there is an offset of 7, 14, 21 etc. days. Now we don’t get the date field plus 7, 14, 21 etc. days.

The intention is therefore course start date plus offset of the course component is the date of the course component.

Who knows a solution for this

Have a look at the documentation ATilma:

Hope that gives you a quick insight to what you can do. What you require should be relatively simple to achieve.

Dear Dave, So far it was also clear to us.
The problem is that we have three fields, namely: Start date, offset and course date
Start date + offset (for example 7 or 14) = course date. We need this to be able to schedule automatically.

You can do that with a simple repeat

If, say your date (varDate) was 05/04/219, repeat 10 times (varDuration) and offset (varOffset) is 7 (days)

Then set up a repeat on the duration (10) and add offset+the repeat index ($index)
So your code would be:

          <div id="repeat1" is="dmx-repeat" dmx-bind:repeat="varduration.value">
            <p>{{varDate.value.toDate().addDays($index*varOffset.value)}}</p>
          </div>
        </div>

Do you just want to insert these dates in the database, depending on what the start date is?

That is indeed the intention. The start date and offset are already known. Now only the calculation from the start date + offset to course date.

If you need to calculate the duration just use (enddate-startdate)/offset

So can you enter a series of rows into the database with that principle? Startdate - Enddate and insert each date from the start date and each day after until the end date? If so, could you give me a hint at where I should start. I was just about to start on this part of a project this morning! Ha… Any help would be much appreciated!

This is untested and off the top of my head but should work ok, hope it is what you want

If you want to add a series of rows starting at “startDate” at interval “courseInterval” until “endDate”

Send those as parameters, say $_POST.

Within a server action

Set you database connection;
define a var or session (i prefer session, saves scope issues) called courseDate
set the value of $_SESSION.courseDate to $_POST.startDate

then a while loop

while $_session.courseDate is less than endDate

set a database insert server action to set the course date to $_SESSION.couseDate (and any other data needed i.e. name,. course reference etc)

then add the courseInterval to $_SESSION.courseDate i.e.
({{$_SESSION.courseDate.dateAdd(“days”, $_POST.courseInterval)}})

The loop will continue making the inserts until the $_SESSION.courseDate becomes larger than the $_POST.endDate on which time it will stop

You should end up with something like this:

Edit: you may have to play around with making sure that the inputs are handled as dates and not strings

Thank you so very much. I will put this to the test and report back to you of the results.

@Hyperbytes thanks for this. I’m trying to do something similar to @revjrblack however, I’m looking at incrementing each record insert by 15 mins as opposed to days. If I set say 13/11/19 14:00 as a start date and 13/11/19 20:00 as an end date, it simply inserts one row showing 13/11/19 14:00. If I set the end date as 14/11/19 20:00, then it will insert rows up until 23:24 on 13/11.

I’m thinking that its using the date value e.g. 13/11/19 < 14/11/19 - is there anyway I can compare times? I have tried setting DB as ‘time’ and purely entering time values on POST e.g. 08:00 as a start time and 14:00 as an end time, but it seems < does not work in this instance and nothing is inserted.

Any ideas?

Thanks

Craig

perhaps format the date/time to an ISO string using FormatDate and compare as strings

i.e. 13:20 13/11/2019 becomes “201911131320”

Thanks @Hyperbytes. I think I’ve sorted it by formatting the values to HH:mm, seems to be working as I had hoped. Many thanks!