Does anyone know any proper substitute of MySQL's UNIX_TIMESTAMP(time_val)
for H2, such that applying that function on a JDBC timestamp returns a unix epoch from 00:00:00 01 Jan 1970?
Asked
Active
Viewed 2,074 times
2

Rajan Prasad
- 1,582
- 1
- 16
- 33
-
Possible duplicate of [CURRENT\_TIMESTAMP in milliseconds in h2](https://stackoverflow.com/questions/30720739/current-timestamp-in-milliseconds-in-h2) – astafev.evgeny Dec 21 '18 at 14:48
2 Answers
3
DATEDIFF('SECOND', DATE '1970-01-01', CURRENT_TIMESTAMP())
as answered here: CURRENT_TIMESTAMP in milliseconds in h2
or here: https://gitlab.com/romain.rinie/h2database/issues/211

astafev.evgeny
- 466
- 4
- 21
-
I've tried this and it doesn't seem to be accurate - there was a small diff between the result and the actual Unix timestamp. – yishaiz May 17 '20 at 20:46
1
I've tried the other answer and the result wasn't accurate. In the other answer I get the timestamp in my local time zone (GMT+3 in my case), so it's not the same as the Unix timestamp (in milliseconds). In my answer, I get the result in UTC.
This would give you the correct current UNIX epoch:
SELECT EXTRACT (EPOCH from CURRENT_TIMESTAMP())

yishaiz
- 2,433
- 4
- 28
- 49
-
2While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – β.εηοιτ.βε May 17 '20 at 22:35
-
Thanks for the feedback - I've edited my answer to provide more context. – yishaiz May 18 '20 at 05:23