How to create future month ends


I was wondering if anybody can help me in creating the right future month end date in the DB starting from any initial date. Let me try to better explain it.

In my application users can create new cash flow forecasts starting from a month end date of their choice. The input is the starting date (from a list or calendar, does not matter) and there is a “CREATE” button. When the button is clicked I run a backend workflow that creates a number of rows (usually 6) in the “forecast periods” table. What I do is to pass the starting date in the backend workflow and create a new thing with the “end date” equal to starting date + month: 1, starting date + month: 2, starting date + month: 3, and so on.

What happen is this. When the starting date is the last day of a month with 31 days, there are no problems since Bubble take care of adjusting the ending date to the last date of the month. So, if for instance the start date is January 31, 2020, the first forecast period calculated as January 31 2020 + month:1 is not February 31 2020 but February 29, 2020. Correct.

But when the starting date is, let’s say, the 30th of a month, what happens is that all the future dates created by the backend workflow are not the end of the corresponding month but are the 30th of the month. For instance, if the starting date is June 30, 2020 the first forecast period will be July 30, 2020. The problem is that I alway need to save the last day of the month. In the example, I need to save July 31, 2020.

Any idea about how to tell Bubble “create a new date as this date plus month X and set the date as the last day of the month” ? Thank you so much for any input.


I solved this exact problem.

You take the last period begin date + months (2) + seconds (-60)

So end date = Jan 1, 2020 12:00am + 2 months - 60 seconds = Feb 29, 2020 11:59pm

Thank you, @robert. But I think that this does not solve my issue. Let’s say that a user pick up as beginning date April 30, 2020. My goal is to create 6 rows of the table “budget periods” that lists:

period 1 = May 31, 2020 12:00am
period 2 = June 30, 2020 12:00am
period 3 = July 31, 2020 12:00am
period 4 = August 31, 2020 12:00am
period 5 = September 30, 2020 12:00am
period 6 = October 31, 2020 12:00am

If I understand correctly what you are suggesting, for the budget period 1 (for instance) I should do

April 30, 2020 12:00am + 2 months - 60 seconds = June 29, 2020 11:59pm (which is not my goal).

I was hoping that there was a function or some available instruction that tells Bubble to select the last day of the month. Maybe a plugin or something …

OK @stefanof. I think I understand the problem better now.

So, can the user only pick an end of the month date as the starting date?

If so, then you could do this:
have a hidden input where initial content = user’s selected date + days(1)
So the result, using your example of April 30, 2020 12:00am = May 1, 2020 12:00am

Then your workflow creates the 6 items as such:
Period 1 = hidden input +months (1) +days (-1) result = May 31, 2020 12:00am
Period2 = hidden input +months (2) +days (-1) result = June 30, 2020 12:00am
and so on, adding +1 month

This topic was automatically closed after 70 days. New replies are no longer allowed.