Adding days to a date on click

Trying to add or take away days on a date text field. The text is an onload variable that just grabs the date. The arrows next to the field need to add or take a day when they are clicked. I’m making a mess of variables at the moment.

How are you representing the date? Here is an example of handling date changes so the day, month, year can increment/decrement and wrap when needed, so if you increase September 30, it rolls to October 1, if you increase October 31, it rolls to November 1, etc. …The OnLoadVariable is automatically set on any change.

DateWrap.rp (75.2 KB)

Thanks for the response.

The date has to be represented like this: 21/8/2018 (with arrows on either side that either take you a day forward or backward. Easy enough to do other ways, but I need the actual date pulled in on page load.

So you’re looking for one string with the formatted date, then adjust the date on that string? You could fake the string with the method I had by hiding the text field borders and pushing them together…

Or use that one string and parse it by the slash (’/’) character. Easier to have individual variables for Day, Month, Year though, and just assemble them together into one string.

See Page 1 of this updated file:
DateWrap.rp (99.6 KB)

There are at least two ways to simply get a formatted date string and both are in OnPageLoad. You can swap their order to test each one…

[[Now.toLocaleDateString()]] … If you are in non-US country this should look like 21/8/2019

[[Now.getDate()]]/[[Now.getMonth()]]/[[Now.getFullYear()]] … Forces day/month/year format

Then I also set global variables for Dy, Mo, Yr to track these separately. I could also use hidden text widgets or parse the date string in real-time with [[ LVAR1.substr(0, LVAR1.indexOf('/')) ]] for the day, etc. It just makes conditional statements a bit more cumbersome and harder to follow compared to using separate global variables.

The basic logic works the same: pressing the arrows will increment or decrement the day (Dy variable) then move the date widget. The resulting OnMove event handles all the conditions of wrapping to next or previous year and month.

1 Like