D
D
Dos2021-01-06 16:44:12
PostgreSQL
Dos, 2021-01-06 16:44:12

How to do the same in PostgreSQL?

Hello. While new to PostgreSQL. Can you tell me how to make such a conversion function?

UNIX_TIMESTAMP(FROM_UNIXTIME(from_at, "%Y-%m-%d 00:00:00")) as date


Given function from MYSQL

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaLuTkA_UA, 2021-01-06
@MaLuTkA_UA

If I understand correctly what you are doing and in from_at you have unix, then you need to do the following:

SELECT EXTRACT(EPOCH FROM to_char(to_timestamp(from_at), 'YYYY-MM-DD 00:00:00')::timestamp);

S
Slava Rozhnev, 2021-01-07
@rozhnev

If you need a UNIXTIME for the start of the day, you can use this option:

select extract(epoch from date_trunc('day', to_timestamp(from_at))) as date;

You can experiment with SQL queries here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question