Convert text to date - quick tip

Bubble doesn’t have a native “convert to date” expression so when you’re using a ternary expression (i.e. format as text) and you want to input a default date, it’s not as easy as you might think.

e.g. If you want to create a new Thing with a default of today’s date (e.g. when no date is selected for your Thing) you can try the equivalent of:

DateSelector.value.is_empty ? CurrentDateTime : DateSelector.value

And it will complain that it’s expecting a date but you’ve given text.

Solution?

Toolkit to the rescue…

  1. Drop an “expression” element on your page
  2. Put the expression within new Date (‘’)

  1. Use that Expression.value in your workflow instead of your input’s
  2. Bask in the feeling of you solving something using Javascript in your no-code app :flexed_biceps:

Hope it helps.

Nice tip
Do you know a workaround for server side expressions?

I want to maintain the “things” date if the user did not provide a new date, similar to “:defaulting to” for text values.

Another option is Better Date Parser which does same thing but introduces a plugin dependency (though supports any date format including plain text / in strings) Better Date Parser Plugin | Bubble

Thank you George, That worked, i had to format the date as ISO for it to work perfectly.

Another question concerning :defaulting to. I don’t know if it a bubble limitation or general something, but is there a way to implement :defaulting to on a list field? without setting a condition on the action. similar to how you’ll handle a text filed. (server side)

any method for backend workflows?

^ better date parser plug-in has a server action, or you can do a similar thing as text to JSON by calling your own backend workflow which returns the date