is there an easy way to convert `timestampz` to ju...
# help
p
is there an easy way to convert
timestampz
to just date / time / zone? I have tried
.toLocaleString
but it doesn't seem to work
n
Hello @Paul! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
🆕 converting timestampz to human readable
c
timestampz does NOT actually store any timezone info - the timestamp is still stored in GMT but the modifier instructs the DB to make any necessary conversion BEFORE storing the date. For example, try this in your preferred DB console:
Copy code
select '1999-01-08 04:05:06 -8:00'::timestamp with time zone;
n
converting timestampz to human readable
c
you can extract the date by casting the timestamp to a date like this:
Copy code
select now()::date;
Similarly you can extract the time by casting to time:
Copy code
select now()::time;
p
how could i do that within React? I am just displaying the table info like so
Copy code
<td className="px-4 py-2">{log.created_at}</td>
so just using
.select('*')
when pulling it
c
oh - when you said timestampz I thought you were talking about SQL or PLpgSQL
I don't think there is timestampz in JavaScript - you only have the Date type - is that what you are talking about?
p
yeah i just need to convert
2022-05-18T14:03:45.78706+00:00
to a readable format
c
if you are fetching a timestampz column from the db via Supabase REST call, I think that gets converted to a string in JSON, so you need to construct a Date object from that string
and then you can extract all the parts using the Date object
p
great thanks
that is helpful