Convert unix time to date field

I’m using an API workflow to capture a Stripe event, however Stripe uses unix time for their date fields. Could the date field be updated to support unix time format?

Otherwise is there a way for me to convert the unix time to the correct date format?

That is a date. If you set the field to date in API Connector > Returned Values window, it should turn into what you are expecting.

I know it’s a date.
I have set that field type to be “date” when detecting the request data.

However when the workflow is triggered the date value is not being stored.
I assumed it’s because it’s trying to write “1538199710” into the field and it doesn’t recognise it.

Anyway I managed to find a plugin (secondsToDate) to do the conversion.

Could be bugged. I’ve not tried that. But docs say that Unix time stamps will come across as dates. If it doesn’t, file a support ticket/bug report. I just did that on date ranges (which aren’t even documented). You’re one up on me!

Stripe returns seconds and Bubble expects milliseconds.

Some discussion here with some workarounds:

Another workaround which is handy if using API workflows: a plugin that sends the seconds to MathJS API and returns the result as date form.

1 Like

Yes, this worked for me:

http://forum.bubble.io/t/timestamp-jan-18th-1970/31875/9?u=rudo

Using the method suggested to set current time set to 1/1/1970 +seconds works. However I have to do this in a number of places. Is there a better way to reuse this logic rather than reimplementing it everywhere?

1 Like

Am I setting this up wrong?

How come I can’t access the date in step 2 after taking a string (unix timestamp) and converting it to a date in an api workflow?

I have the exact same problem, and this looks like a perfect solution, however the links are broken and I can’t see what the solution is :frowning: Does anyone have a working link to these screenshots? (I assume they’re screenshots!) :pray:

2 Likes

@emmanuel any idea if this is being fixed in the near future? Is Stripe an outlier here in sending seconds vs. milliseconds or is this something that might have a fix in the future.

This is an action but I need to print data. Thoughts?

To be clear, what is the feature need, to be able to convert a timestamp in seconds into a date?

We shouldn’t have to use a plugin for this.
On a Stripe object like Subscription, there are dozen of dates !

2 Likes

Unix timestamp is in seconds. Javascript likes milliseconds.

Annoying, but you can * or / by 1000 in most cases to get the number you need. Took me ages to workout the first time I got seconds though.

My use case is to turn the unix timestamp that Stripe sends back into a date. Right now, if I change the API call to recognize it as a date, it shows up with a 1970s date. If I change it to be a number, there’s no where for me to format the number as a date using the Unix timestamp logic.

One fix would be to let you treat a number as a unix timestamp and let you format as a date.

Another potential fix -> in the Bubble API, when making a call I can change the format to date. Maybe it’s possible to let you choose how to format the unix timestamp.

Open to other suggestions, but when I’m wanting to print the unix timestamp as a date, using a plugin doesn’t work. I.e., “Your next renewal date is [Unix Timestamp Formated as Date w/ Milliseconds].”

I’m also struggling integrating Intercom at the moment because of the need to send it UTC Unix formatted dates, it would be great if Bubble could handle this type of date format natively.

All the plugins that did it seem to be broken.

Perhaps I’m misunderstanding, but is there any reason one couldn’t simply initialize a date to 1/1/1970 and then “change seconds to”?

For example, the following seems to work for me…

Here’s the result (using the value from the image in @vagung’s post) …

44%20PM

…which is exactly what I get when the same value is entered into the following site…

9 Likes

Thanks for that info, @sudsy!

I have this setup and it’s converting the time to UTC. How would I get it to adjust based on the User’s current time zone? Selecting User’s current time zone in the Time zone selection doesn’t change it.

Did you get this figured out, @telaholcomb? If not, it’d be helpful to know the value and the context. What exactly is the number of seconds, and from where is it coming?

Not yet. Figured I’d give my brain a break and circle back. Thanks for responding!

Example value is 1614704020512 and it’s coming from 3rd party app (Streak) through API.

It’s milliseconds so I divided it by 1000 first.


⠀⠀⠀
⠀⠀⠀
Then added those seconds to 1-1-1970


⠀⠀⠀
⠀⠀⠀
It comes out to the right date in UTC and doesn’t change when displayed for different users based on their timezone.