Timestamp convertion to Date(UNIX)

Often enough API’s return timestamps to represent certain date and times. I found a very cool trick using Bubble’s built-in Date (UNIX) that allows you to automatically convert the timestamp to a date.

Bubble recognizes them as a number so you’ll need to modify the response manually.

The result:

Screenshot - 2021-04-03T092832.220

7 Likes

Unfortunately, @nocodeventure, I’ve found this type doesn’t actually render correctly (unless I’m doing something wrong) when the date (UNIX) typed field is then displayed in an RG. For example, this is a configuration I’ve made for a Get API call:

But THIS is what I get when I display the “created_at” field’s value in a Text element. :frowning: The right-hand value is the actual value extracted to UNIX, which converts just fine.

image

Any tips on getting the value to ACTUALLY display correctly? I’m sure I’m just missing something…

Try multiplying that number you’re getting in times 1000

The Unix option is looking for milliseconds. That’s why you’re stuck in 1970 up there

My eyes could be deciding me at this hour

Thanks for the post. Unfortunately, Bubble doesn’t give the option to multiply a value formatted as date (UNIX).

image

I’m sure I could change the type for the call response, but I was hoping Bubble had some kind of native solution. Any thoughts?

1 Like

@eLPDev

3 Likes

it was working for me, I’ll have to check again though.

Thanks for that, @cmarchan. I was using that feature, but I’m trying to figure out why Bubble’s Date (UNIX) type doesn’t render the same thing as the Unix Extract. For example, using that Extract from date feature renders a legitimate UNIX Epoch timestamp that is accurate.

Editor:
image

App (Date (UNIX) on left, Unix Extract on Right):
image

The first stamp renders as follows when plugged in to the Epoch Converter:

image

Does that make sense?

This is because the Date (unix) gives you seconds where as Bubble.io extract Unix gives you milliseconds.

Im not sure why the inconstancy but as @jared.gibb said you then have to multiply by 1000 to put the Date(unix) into milliseconds.

I also use the Epoch converter and you can see there it says timestamp in Seconds because it is realizing it is getting seconds by looking at the length of the number.

3 Likes

Please i havee this exact issue …i cant find the option to even multiply by 1000

Just to add on to this topic. Stripe returns the unix timestamps in seconds, hence why this method works. For other api’s they might return MS, in that case this won’t work.

2 Likes

Any idea why subscription schedule update call gives error 400 says bad request when i send date time to unix timestamp in miliseconds? or seconds. or how can i convert bubble datetime to epoch timestamp?

[date time]:extract UNIX Timestamp

yeah m using that but stripe api gives error as a bad request. that timestamp is in miliseconds sometime it takes and sometimes throws error saying value should be lesser than 9999999999

Try displaying that same value in a text element to see what it is sending to Stripe. Like right now the unix time is 1694620794 (in seconds) which would be under that error they are giving…

But their docs say milliseconds??

i am trying to convert datetime to unix timestamp that gives miliseconds which is 13 digit. how can i convert them to 10 digits

when i am trying to devide that number by 1000 it givves decimal points i just want to remove that. format as number will return text so i cant use it. and floor and ceiling returns 0

Screenshot the number you’re working with. :floor and :ceiling will bring it to the closet whole number but shouldn’t 0 it out. Or just add :rounded to 0 instead

used another plugin that solved problem of 10 digit unix time stemp.

cheers mate thanx for your time and effortws.

really appreciate it.

regards and thanx

1 Like

@karan_trivedi248 Please what is this plugin? Please share with me.

Unix time converter Plugin | Bubble

this one