Convert text to date

I wish to extract 3 numbers from different positions in a string and use these to form a date. Using combinations of truncate and truncate to I can extract the numbers, but I am sure there must be a more elegant way to do this. Previous suggestion was to use “Extract with regex”, which requires me to learn the rather arcane regex conventions, so I am sticking with truncate for now…

My real problem is how to convert these extracted numbers to a date which I can then display as the initial content of an input field of type date.

I am sure the answer is trivially simple, but I have now spent a week trying to find it.
All suggestions gratefully received.

What is the format of the date you want to parse ?

I have extracted the date values to 3 state variables (day, month, year). I now wish to assemble them into a date, preferably in dd/mm/yy format, but any date format will do. It appears I cannot add more than 1 state variable to the initial value of the BirthDate input field I am trying to setup, although I can do this in the placeholder.

I am extracting the date from an ID number field formatted as yymmddxxxxzzz.

I hate the give you a “it works for me” answer, but I am able to use multiple state variables to an input elements initial content. I do often find it hard to place the cursor in just the right place to put a string character in between dynamic content, so perhaps you are having the same issue.

date format

I have no problem inserting string characters into an input field of type text. My problem is how to convert a text string such “05/12/50” into a date acceptable to an input field formatted as date. See the error message.
Surely, surely there is a convert text to date function somewhere out there.

1 Like

Ah, I see. Well, I went back to my example and oddly found that I could not get it to work despite it having worked before (as evidenced by the screenshot). I played around trying to figure out how I made it happen and I think I figured it out, though it seems…almost like a bug.

Set the input element’s content format to TEXT and enter the same content you have in the placeholder to create a date. Then, change the content format to date. It will work then. I have no idea why that is.

Thank you for your suggestion - it does work. However, it is a pure and simple hack which leaves an outstanding issue in my app. I do hope that Bubble staff are seeing this and will propose a less hacky solution.
BTW, is there anyway to turn off an issue, to say I am aware of it but will live with it?

1 Like

It is indeed fairly tricky, however it is possible using the “Expression” function from the toolbox.

Set the expression to be your date in text form, and you can use it as a date.


Another method is to use a Toolbox Expression and construct a javascript date, then configure the Expression element to return the value as a date.

Expression: new Date(2010,1+11,19)
That would return a date for midnight starting 19th December 2010, in the current timezone of the browser. Note that in javascript the date starts with 0, hence the increment included.

Whichever way you create the date, be aware that a date of birth is normally in context of a timezone. If you ignore the timezone component, the date may be different by a day either way, when displayed in another timezone. Possibly this doesn’t matter for your app.

Haha Nigel, good timing!

@base37 my post covers the expression, Nigel’s post covers how to use it =)


Just beat you to the same answer :slight_smile:

In my case I have a date coming back as a text from an API call. The API connector won’t recognise it as a date, so the toolbox comes to the rescue. Think you can do the same with your dates.


Neither method results in a value in my input box.

Tick the “data has no executable code” box.

Still no result. I assume my environment does not support javascript, hence the long execution error message. For some reason 01.01.1970 is returned in the 2nd case, no matter the source values.

Can you show the properties of the input box?

Note, the placeholder text is only shown when the box is empty, and doesn’t contribute to the value entered. So usually it is used to prompt the user with a suggested format.

The initial content sets the value of the input box, but only if the user hasn’t changed it … although you can use the workflow actions reset inputs or clear group to get the input box to throw away the user’s changes and resume using the initial content.

I am at a loss as to why my Toolbox expressions don’t appear to evaluate when used in text or input boxes. I cannot get a text box to display the current users name from an expression. When are expressions evaluated?
I have read the examples on Toolbox, and can see no differences. I am not currently on a plan (waiting to finish app) - is that perhaps a reason?

Error message received.

Input box for date

Expression to evaluate date

Expression to evaluate date

Javascript is case sensitive, new date(...) has a different meaning to new Date(...) . It is very particular about what you put in, which is what syntax error means.

I recommend you confirm what you want to happen …

  • Open the browser’s development area by pressing F12
  • Typing into the console: new Date(2010,3,17)
  • Then try experimenting with different syntax and numbers and functions.

I finally have the text to date process working. The solution was not trivial after all.
I would not have stumbled upon the tools plugin without help from you guys. Since expressions are so important, perhaps you should add a mention of this plugin into the manual and reference.
Many thanks to you all for your help.


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