I have passed the result of Date.now()
and other plain Unix timestamp values like 1534360109480
into SQL and ran them through this:
"@converted_date" = to_timestamp("@date") AT TIME ZONE 'UTC';
And it consistently returns 50591-11-28 22:32:38
.
I do not understand how the year could possibly be 50591 and the date/time is not accurate beyond that anyways.
What am I doing wrong?
1 Answer 1
to_timestamp
accepts the epoch value ("Unix time") with second precision, while your value seems to have millisecond precision. You need to do something like
to_timestamp(@date/1000) AT TIME ZONE 'UTC';
-
How can I exclude the "second" ? Above code gives me "2022年11月17日 06:27:15" and I want to remove secondKaveh Naseri– Kaveh Naseri2022年08月17日 14:38:49 +00:00Commented Aug 17, 2022 at 14:38
-
You seem to have a different question @KavehNaseri, so please ask one.mustaccio– mustaccio2022年08月17日 15:05:33 +00:00Commented Aug 17, 2022 at 15:05
@date
...now()
intoto_timestamp()
Date.now()
" or "a unix timestamp" are no specific values and leave a lot of room for interpretation. E.g. I supposeDate.now()
refers to any OO language, but which? Please show actual values as the database sees them or at least elaborate on how and in which environment you pass the values, so that people familiar with that environment may deduce the values, that reach the DBMS.1534360109480
to be converted to something like2018年08月15日 18:20:30
in UTC