what is epoch time and how to convert into standard date format

 


what is epoch time?


Epoch time, also known as Unix time or POSIX time, is a system for representing time as the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970. It is widely used in computer systems as a standard way of representing time and is often used in databases, operating systems, and programming languages.


Epoch time is represented as a 10-digit integer, which represents the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970. This integer value is often referred to as a Unix timestamp or POSIX timestamp.


For example, the epoch time for 12:00:00 UTC on January 1, 2022, can be calculated as follows:

timestamp = (number of seconds between epoch time and 2022-01-01 12:00:00 UTC)

          = (1641062400 - 0)

          = 1641062400




How to convert epoch time to Regular time in Oracle SQL ?


SELECT TO_DATE('1970-01-01', 'YYYY-MM-DD') + NUMTODSINTERVAL(epoch_time/1000, 'SECOND') AS regular_time FROM dual;


we have to divide epoch_time by 1000 in order to convert milli seconds to seconds 


postgres: SELECT FROM_UNIXTIME(epoch_time) AS regular_time FROM some_table;

oracle SQL: SELECT TO_CHAR(TO_TIMESTAMP('epoch_time', 'SSSSS'), 'YYYY-MM-DD HH24:MI:SS') AS regular_time FROM dual;

Comments

Popular posts from this blog

How to make CRS and ASM not to restart after server reboot

How to replace ASM failed disk?

Shell scripting cheatsheet