Is it possible to transform a text parameter (for example as the output of a ‘formatted as text’) into a date/time to pass to a field that accepts the data type date?
Thanks for your help.
I am assuming you want to use a text as a date dynamically.
If you actually set the initial value of a datetime picker to an arbitrary text that is a date formatted as simplified extended ISO it will be recognised by the input. The problem is that bubble will tell you it’s an error.
With plugins you can actually perform typecasting of strings into any other value, assuming the string is properly formatted for that type.
A workaround can be to use the operator “get data from page url” and manually specify the type of the data. Again, you need to pass a date formatted as simplified extended ISO to make this work.
Of course if this date is dynamic it’s probably coming from the database or an api request, so you should be able to set the proper data type and this workaround should not be needed.
Thanks for your answer!
My problem is specifically when a variable has been set to text by bubble editor through a function like the ‘formatted as text’.
Even if this text corresponds to a simplified extended ISO date, how can I make Bubble to accept it?
Haven’t tried the first solution your mentioned with the initial value set by a text that represents a date, but if this leaves an error in the ‘issues to fix’ panel like ‘should be date but right now is a text’ then this wouldn’t be a suitable solution as errors like these block the deployment to production environment.
So you have a date but you transform it to a text and you want to reverse it back to a date.
Can you just save/handle 2 different values? Like you keep the date as a date and you add the date converted as text in another state/field.
I want to set the minimum date/hour of a date/time picker element conditionnally.
I’m thinking about using what bubble currently offers us as a “If then else” which is the “yes/no formatted as…”
so that I can return a certain date/time value for “yes” and a different one for “no” but bubble enforces a text data type returned by this function.
You need to think in a Bubble way.
To set the minimum date dynamically you need to add a condition to the input.
To recreate an if else you need to add two conditions and set the expressions accordingly.
For example if you want to recreate if count > 0 min-date is X else min-date is Y
you add one condition count > 0
and set min-date to X. Then you add a second condition with the opposite expression count <= 0
and set min-date to Y.
I hope this helps.
Mariano
Or you can explore JavaScript to help you…
Editor is here.
Hi Dorilama,
thanks for your answer, I manage to get the condition working but it doesn’t output the correct data type, as per my original question.
it will never output the right type if you use “formatted as text”. The point of creating 2 conditions is that you put an expression that ends with yes/no in the condition and set the value with a date. All the logic stays in the condition and you just use your date directly as the value.
Cheers
Mariano
OK I got it now! I didn’t understand earlier what you meant by condition, I was too focused on using the yes/no formatted as…
Thanks a lot for your time and help!