How can i convert this string to a int8 in PostgreSQL 12?
2021-10-18T17:45:22Z
i tried:
TO_TIMESTAMP('2021-10-18T17:45:22Z'::text,'YYYY-MM-DD hh:mm:ss ')::int8
to_char('2021-10-18T17:45:22Z', 'YYYY-MM-DD hh:mm:ss ')::integer
and a few variations of these but without any success.
The Input string cannot change because it is passed this way by an external software.
CodePudding user response:
You didn't tell us what the integer value is supposed to represent. One general approach here would be to work with UNIX timestamps. For example:
SELECT EXTRACT(epoch FROM '2021-10-18 17:45:22'::timestamp); -- 1634579122
The value 1634579122
is the number of seconds which has elapsed since January 1, 1970.