Forum Academy Marketplace Showcase Pricing Features

Anyone know how to convert :formatted as text result to date?

I have a workflow in which I need to conditionally set a thing’s date. I can get the conditional part just fine, but the problem is the thing’s Date field is…well…a date. Because :formatted as text creates a text, I can’t use the text output.

image

Really hoping I don’t have to create multiple conditional steps in the workflow as that will be a pain to manage. :cry:

Any clever ideas?

@eLPDev

Create a parallel text field for the date and populate both

1 Like

Yup. What @cmarchan said

Have 2 fields on your dB item. One for the formatted text date and one for the date/time stamp

1 Like

@cmarchan and @jared.gibb, thanks for responding! I’m not sure I’m understanding, though. How would I convert the conditionally formatted as text result to a date? The Yes and No values are both dates, but Bubble apparently doesn’t keep the data type.

Using the formatted as text operator will turn any data type into a text type and only display the values rather than create the values in the same data type.

So when you have date fields in your yes/no sections for the format as text, both are being turned into a text object.

But what you are doing is completely possible, just needs the proper setup and tools.

First here is a quick look at the setup and result

Screen Shot 2021-09-03 at 12.34.17 PM
Screen Shot 2021-09-03 at 12.34.11 PM

Need an option set or at least something that will store the value of Jan 1, 1970…this is what I call ‘dawn of computer time’…I think real term is ‘epoch’…Every date is just a number of milliseconds since that time (once you understand that, you can understand how to manipulate date objects much more easily as they are just numbers).

I have mine in an option set

Then you also need to have a way to get the User’s Timezone UTC offset in minutes…I use free plugin ‘Browser Timezone’…you will also need to multiply that value by -1 to get the correct value to use…I stored mine in a custom state

Screen Shot 2021-09-03 at 12.37.59 PM

So in my example, I have the dynamic expression start with the option set value ‘dawn of computer time’ (Jan 1, 1970)…this is followed a “+ seconds” operator and that value is set to some expression that can evaluate to a yes/no field so I can do the formatted as text

My formatted as text operator just takes current date/time…you would use whatever date values you want for the date, but then do the operator ‘extract’ and extract the unix time stamp (the number of milliseconds since Jan 1, 1970) and then divide that number by 1000 to arrive at a number of seconds since Jan 1, 1970.

From there you now have text data, but need it to be a number so after the formatted as text operator use the ‘convert to number’ operator…now you can follow that with a “+ minutes” operator and that value should be the custom state that is the (-1*UTC offset).

And now you have a date value that you can use

1 Like