Justin Slabbert


How to convert Date from Firebase Into Draftbit Readable

Hi guys,

I thought I would post this as a how to for people in case they get stuck.

๏ปฟ Nick Selman ๏ปฟ gave a really great tutorial on how to transform data, however, for Firebase, you sometimes would need to convert dates to readable format as it stores in Epoch format. To do this with Draftbit, I found that you need to transform the data but not worry about the firebase functions that exist and rather use pure existing javascript functionality.
๏ปฟHere is the code. It can be simplified but I wanted to give a full breakdown.
originalDate = userDate;
dateConverted = userDate * 1000;
convertedDate = new Date(parseInt(dateConverted)).toLocaleDateString("en-US");
return convertedDate;
I found that no matter if you choose toSeconds or toMiliseconds in Draftbit for the variable, it still uses miliseconds in the custom code. Make sure to multiply by 1000.

Remember to set your transform with to your new function wherever you are using it.

This returns the date into mm/dd/yy format. You can change your locale string to whatever you would like.

Hope this helps someone else.
Like Comment