ANSI UNIX_TIMESTAMP () Standard

UNIX_TIMESTAMP () is not a standard ANSI keyword, but an addition to MySQL syntax. However, since I support multiple databases, is there a standard ANSI way to write UNIX_TIMESTAMP ();

thanks

+3
source share
2 answers

As far as I know, no.

Each database handles this differently.

For example, in Oracle, you must manually create a timestamp with something like:

SELECT (sysdateColumn - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400) AS alias FROM tableName;  

In MSSSQL:

SELECT DATEADD(s, yourDateColumn, '19700101') AS alias FROM tableName

In PGSQL:

SELECT date_part('epoch', timestampColumn) AS alias FROM tableName

Edit: as Alexey Kuznetsov noted , there are two completely different ways to use the MySQL function UNIX_TIMESTAMP(). I suggested the latter, UNIX_TIMESTAMP(date)(to convert the original format into an era) for the above answer.

+2

UNIX_TIMESTAMP : UNIX_TIMESTAMP () "1970-01-01 00:00:00"

DATEDIFF

+1

Source: https://habr.com/ru/post/1711534/


All Articles