Date addition (Specific purpose)

I need to make a payment day label for credit cards

User will input the “Statement Day” as digit eg:- 24 (means 24th of every month), Then i need to show the element with date as “24/07/2019” and “payment day” as +50 days from the statement date, so it need to show as “18/10/2019” how to achieve this in bubble.

My date “24/07/2019” is created with the formula

Element’s Statement Day/Current date/time:formatted as 07/2019

Any help is appreciated

Something like this?
http://www.giphy.com/gifs/ReVo0InW2oOVFX9DlZ

For your day input, make sure you set the content format to Integer and set the initial content to whatever number you would like to be default. If you leave this blank, the calculated date will default to the last day of the current month.

image

So let’s get the current Statement Date. To do this, we are going to use the Current Date/Time and the Change Date To modifier that is available in Bubble when working with dates.

The date we are going to change it to is the number that was put into the Day input.

The expression will be:

Current date/time change date to inputDay's value:formatted as dd/mm/yyyy

What this expression does is says “Hey Bubble, I want the current month but can you pretty please change the day of the month to the value we entered into this specific input?”

To format it, we will use the Custom option and use the format dd/mm/yyyy to get day/month/year.

So that will give us the statement date. You can use this in a text field or an input field in the event you need to reference the specific value in a workflow.

Moving on to the Payment Date.

It will be very similar. We will use the same expression with the addition of the +(days): modifier with a value of 50.

This expression will be:

Current date/time change date to inputDay's value +(days): 50:formatted as dd/mm/yyyy

This expression says the same thing as the one we used to find the statement date but then says, “Oh yeah, please add 50 more days to this day too. Thanks!”

There you go. That should do what you are needing. These same expressions can be used in workflows as well to save the date values. No ‘formatted as’ needed if using in a workflow of course :grinning:

2 Likes

All problem solved!!! You are the bubble master…:grinning:

1 Like

@eli - How can i show “Number of days to make payment”

it need to show as "Payment date - Current Date = 20 Days ". I tried - operator with Payment Date value, but no hope!!!

@melon, you can use math.js to do this and I think there are other plugins that do similar things. But it’s very simple to do with standard Bubble features as well.

http://www.giphy.com/gifs/cKWOkK50LvFGe1lH4D

The first thing you have to do is convert the dates to a number we can run math operations on so we can subtract the current date from the payment date. To do this we will use the :extract operator on the end of the date value.

In the options here, we could extract the Date which will give us the day of the month, however, that won’t take into account for crossing over the end of a month.

For example, if my payment date is August 31 and the current date is August 15 that will work fine. We can extract the days and take 31 minus 15 and get an accurate answer of 16.

However, in that same scenario, if my payment date is September 5 then it won’t work because we are calculating 5 minus 15 for an answer of -10 days til my payment is due. Obviously that is incorrect.

The option we want to extract from each date is the UNIX timestamp (ms) and then subtract the Current date’s UNIX timestamp (ms) from the Payment date’s UNIX timestamp (ms). This will give us the time between both dates in milliseconds.

image

The formula for finding the days then is to simply divide the milliseconds by 86,400,000 (1,000 milliseconds per second * 60 seconds per minute * 60 minutes per hour * 24 hours per day).

You will need to format as number and set the decimals to 0 so you get whole days.

The entire formula will look like this:
image

This is not feasible in the current scenario as Payment date is formulated with bubble formula only (as per your first solution) so when payment date is automatically generated (Statement date + 50 days) since its not a date variable (no date pickers) this calculation is not moving forward…

You can store that of course and do all sorts of other stuff. Write it to the db, store it temporarily in a custom state, etc.

1 Like

I tried most options, and finally got it working through “text to date” plugin Data Converter. Initially it was giving - (negative) values, i was searching for an ABS() formula in bubble, on the end it was just a calculation mistake to minus big number from small…All resolved.

A question still remains how to remove - (negative) operator from a number, like absolute…?

Multiply by -1 inverts the sign of a number, yeah?

An ABS() function is just this (pseudocode follows):

  1. We assume we have some value, let’s call it “v”

  2. If v is greater than or equal to 0, do nothing. Return value v.

  3. If v is less than 0, return v multiplied by negative 1.

You can do this in any programming environment, including Bubble.

Edit: fat fingers and squinty :eyes:

1 Like

Aside: while Bubble’s tagline of “You don’t have to be a coder” is true, what they forgot to tell you is that it’s still helpful to know math and computer science.

If you know those things, Bubble is a cakewalk.

Someday I’ll get around to doing more videos like my very very basic video on Booleans, which is still one of the best things I think I’ve done around Bubble.

(If interested, search “cool with boole” here.)

2 Likes

Sounds like you got it working but as Keith notes, these are just the expressions to get your values. Date pickers, date inputs, custom states with date values, they can all be used the same.

For instance, you can create a workflow that runs when the statement date is changed that sets a custom state with the value of the payment date. Then simply reference that state for your value anywhere you need to display the payment date or make calculations from it.

Or if you use an input to display the payment date initially you can simply reference that input as well for your value.

Not a recommended way to do it since if I’m referencing a value more than once, I prefer to have a single instance of it, but you can replace “Payment Date’s value” with the same formula used in the initial solution.

Good luck!

1 Like

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