I have a simple t = Date.now;
which goes to Postresql t_time
column declared as timestamp with time zone
via REST API.
I got the error:date/time field value out of range
.
I can't use the answer from this post as I don't write raw SQL but use ORM(Knex.Js). Calling db only to make the conversion looks like an overkill to me. Any other solution in js?
How come I can't find a convertor? Am I missing something?
Note: I just need date and time as hh:mm:ss, I don't need milliseconds.
The TIMESTAMP (also known as TIMESTAMP WITHOUT TIME ZONE ) and TIMESTAMPTZ (also known as TIMESTAMP WITH TIME ZONE ) types stored as a 64-bit integer as a microsecond offset since 1970-01-01 in CRDB and as a 64-bit integer microsecond offset since 2000-01-01 in PostgreSQL (by default).
Introduction to PostgreSQL timestamp The timestamp datatype allows you to store both date and time. However, it does not have any time zone data. It means that when you change the timezone of your database server, the timestamp value stored in the database will not change automatically.
PostgreSQL assumes your local time zone for any type containing only date or time. All timezone-aware dates and times are stored internally in UTC .
PostgreSQL Convert DateTime to Date Using EXTRACT() Function EXTRACT() function takes in two arguments, field and source. The field argument specifies the date part, i.e. month, decade, hour, to extract from the DateTime value. The source argument is a value of type TIMESTAMP or INTERVAL.
Date.now()
only provides the since EPOCH in milliseconds.
You need an ISO date time string. To achieve that, set t
like this:
const t = new Date(Date.now()).toISOString();
console.log(t);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With