How To Create A 'Date' from a Date String?

I’m trying to work with Dropsource mobile app but it won’t work when sending a Date object to a Bubble Date type thing.

How can I receive a Text String (formatted as a date) and convert it into a DATE and save it into the bubble database via an API endpoint?

That’s was the reason I bought the plugin ‘date/time converter’ until I realized it was not working with API Workflow. @levon told me it will be in the wish list, soon? :slight_smile:

Hi @JustinC,
You actually don’t need to do any conversion.
Simply create a page variable of type date and bind it to your api date field.
Then in the Date Picked event, use a Create Date from parts action to create a date object from the picker.
Then set this value to your date page variable.
Finally make your api call.

Ignore the actions marked in red (you only need two actions)

1 Like

Can you link your example Sean? Not sure I caught everything on that one. We talked about API Endpoint (in API Workflow), right?

The JSON passed to Bubble’s API is just text anyway. If you pass the date string in an accepted unambiguous format like YYYY-MM-DD, and in the API Connector tell Bubble this is of date type (not just string/text which it may default to) you should get a date object.

Is that not working for you?

(BTW, yeah YYYY-XX-ZZ isn’t “unambiguous” in general, as 2018-02-01 for example theoretically could be Feb 1 2018 or Jan 2 2018, but I think if passed string and told that this represents a “date” Bubble converts it as a date object representing Feb 1 2018 [YYYY-MM-DD].)

but no (from my testing) :wink:
Customers imports can be in the format dd/mm/yyyy or mm/dd/yyyy (depend on the country).
12/11/2018 or 11/12/2018, how Bubble will interpret it? That’s why a converter plugin will be the best for that part (unless Bubble create one).

Look: Bubble can only interpret it one way, right? Test and see which it is (I think I’m right in what I posted, but test and see). It’s then your responsibility to present your date info to Bubble in a format that gives you the results you expect.

And I was mostly answering the OP’s question in a very general way. @seanhoots answered in a Dropsource-specific way (he’s rather expert with Dropsource and Bubble integration and the original question relates specifically to that).

Anyway, presenting the date string in an ISO date format is truly unambiguous and, if you can do that, that’s the way to go.

I’ve not done much in terms of connecting dropsource and bubble though that’s really interesting to me. But in terms of Bubble, I do a lot with dates and date manipulation and sending dates to the API Connector.

I just looked at one of my own APIs that passes date info back to the Bubble API connector and see that a JavaScript date object passed as a string like:


is interpreted as YYYY-MM-DD being the format. (The time part here means UTC time at time zero - the start of this day.) The date part represents and is understood by Bubble to be NOVEMBER 9th, 2018 (not September 11th, 2018). So what I said above is correct.

Can’t asked customers to change all their imports formats for something else :wink:

I need an action to convert the ‘date string’ received, and transform it to Bubble date. As you said, a date can be imported in many ways (also: yyyy,mm,dd etc… )

Hope you see my point, or maybe something I don’t get?

I need to create an AUTO DETECT import for couple of date formats:

I get what you’re saying.

Are your customers uploading CSV files or using an API call for such imports?

Note that there’s no way really to guess what the date import format is, if you allow date import in various formats. Somewhere, someone has to tell the system: “OK, the dates we are sending here are in format X.”

Converting string dates to date objects on the server side in Bubble isn’t something that’s particularly easy (or even possible) right now. I guess with server-side JavaScript you have access to Date.parse()…

But, once one can install NPM packages (specifically moment.js) and use them in server-side script, taking a wide variety of string representations of dates and converting them accurately to date objects would be relatively easy.

In the meantime, you’d need to take your uploaded string representations of dates, leave them as strings, get the User (or the CSV or whatever) to tell you what the date format is, and you could pass those things to an external API (like a webtask of your own design) that does the flexible string-to-date conversion and passes back dates in an unambiguous format accepted and understood by Bubble.

Moment makes that insanely easy. See the docs for moment’s string and string+format features:

You can also run moment in the page (client side) and I do this all the time. So for some use cases, you could suck the data into Bubble and then send the user to a page where the date conversion would happen, pass that back up into Bubble, and do other stuff there. (Like I said, this would only work for certain use cases.)

The general point is that string-to-date parsing is full of “gotchas” and there are robust libraries for doing this (so I wouldn’t set out to reinvent the wheel here). You just can’t at the present time execute those on the server side in Bubble. (And even if you could, it might not be the best or fastest way to do that.)

1 Like

As you said, server-side will fix the issue here. Not possible at the moment to use the client side (too slow). And yes, I will probably use another server to convert date and put it back to Bubble (for now). Auto-detect will make the ‘hard’ job of detecting the date and convert it.

Bubble will open server-side to install any NPM, just a matter of time now (hopefully) :slight_smile:

If it is one of the types Bubble understands, set the parameter as a date type (manual or automatic parameter detection) and it will convert for you.

What is the format you are receiving? Assuming it isn’t something standard, if you have Toolbox plugin, you can use a Server script to parse the text into a date.

1 Like

You can use a little webtask.

Will share the code if you are interested. It should convert most things.

1 Like

var chrono = require(‘chrono-node’);

module.exports = function(context, cb) {
cb(null, chrono.parseDate(context.query.string));

1 Like

Where can I find the type of dates bubble understands?

Is it a matter of just configuring a string to a format that bubble likes?

Hey @JustinC dropsource sends dates to bubble as Unix timestamps which bubble understands.
So just do what I told you up here and it will work.
I’ve done it several times.


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