jhon.smith
jhon.smith

Reputation: 2043

Mysql Unix_timestamp function

In oracle converting this date 2012-07-03 11:38:41 to unix_timestamp we get

    select (to_date('2012-07-03 11:38:41','YYYY-MM-DD HH24:MI:SS') -
    to_date('1970-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS'))*86400 as unix_timestamp
    from dual
SQL> /

UNIX_TIMESTAMP
--------------
    1341315521

But when i try the same on mysql server

select UNIX_TIMESTAMP('2012-07-03 11:38:41')
1341311921

Server Settings are something like this

**mysql**> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2012-07-26 15:27:31 |
+---------------------+
1 row in set (0.00 sec)

**Unix** >Thu Jul 26 15:27:56 BST 2012

**oracle**>select current_timestamp from dual;

CURRENT_TIMESTAMP
------------------------------------
26-JUL-12 15.27.16.967258 +01:00

How do i make sure oracle and mysql give me the same values ?

Upvotes: 2

Views: 912

Answers (2)

jhon.smith
jhon.smith

Reputation: 2043

I used this trick unix_timestamp(cast(sys_extract_utc(systimestamp) as date

And then i also wrote a function called unix_timestamp

create or replace
function unix_timestamp(in_date date)
return number DETERMINISTIC PARALLEL_ENABLE AS
l_date date;
begin
return trunc((in_date -to_date ( '01-jan-1970', 'dd-mon-yyyy' ))*86400);
end;
/

Upvotes: 1

Pekka
Pekka

Reputation: 449435

The difference between the two values you show is 3600 seconds, i.e. 1 hour.

Most likely, the two servers' timezone settings vary by one hour.

See https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html for time zone info in the mySQL server. Here is some in-depth info for Oracle's handling of time zones.

Upvotes: 1

Related Questions