Hi All,
In my database, I have a timestamp for the record creation which is stored as and passed to weweb as a unix timestamp. What is the best way to convert it to dd/mm/yyyy?
Hi All,
In my database, I have a timestamp for the record creation which is stored as and passed to weweb as a unix timestamp. What is the best way to convert it to dd/mm/yyyy?
I would convert it in the backend. What backend are you using?
Hey Edward, Thanks for replying. I am using Xano.
when you get the data from the database, create a variable in Xano that contains the date and format it. Then you can add it to the response at the end and return it together
In case, here is a quick video as the format can be a bit tricky. Its d/m/Y for UK format (11/06/2022)
Personaly, I wouldn’t do the conversion to a string in the backend.
Timestamp are probably easier to handle for sorting and other calculation (add days or years, calculate time differences,…). And if, at some point, you need to format the date in different format accross you app, having a formatted string to start with will not help.
I would rather avise to create a custom formula that converts the timestamp to a date.
This require a bit of javascript, but nothing too complex I’d think - although there are a few step for the actual conversion (timestamp to milliseconds, milliseconds to Date, Date to formatted string).
Here is a step by step tutorial : Convert a Unix Timestamp to a Date in Vanilla JavaScript
Now, if the webweb teams is reading this : a NoCode formula to format date would be great. don’t you think ?
@Joyce Is there any news on this? I’m struggling to convert a timestamp stored in xano to display as the initial value in the date picker. I have added the day.js extension, but still can’t get there. Please help!
If you have a timestamp you just need to convert it to a date object and then a string. For example: new Date(1670431416145).toISOString()
EDIT: updated code to convert the timestamp into string.
When you add the date extension, you get access to a bunch of no-code date formulas in the formulas tab.
Here’s an example formatting a timestamp:
That’s super cool
Even better because I’m stumbling on that problem and the solution in 21 hours old