2

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 ?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Apologies i forgot to mention that both the servers are hosted on the same Unix box Good observation though
@jhon then either mySQL or Oracle is set to the wrong time zone. Which one returns the correct time stamp for where the server is located?
i have updated the question with current timestamp settings for Mysql Oracle and Unix and they dont seem to be off by 3600Seconds interesting
Pekka thanks for noticing that i was off by 3600 seconds and this important finding by you actually triggered my answer below so I am marking your answer as correct
1

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;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.