I need a timestamp as an integer (please DO NOT ask me why, I am completely concerned about this). The definition is the number of seconds after 01/01/1970, as usual.
What I have as the initial value is a string with the format
YYYYMMDDHHMMSS (e.g. 20140108154821)
I was able to create a regular timestamp
CAST(
(SUBSTRING ( t.thetime FROM 5 FOR 2 )||'/'||SUBSTRING ( t.thetime FROM 7 FOR 2 )||'/'||SUBSTRING ( t.thetime FROM 1 FOR 4 )||' ' ||SUBSTRING ( t.thetime FROM 9 FOR 2 )||':'||SUBSTRING ( t.thetime FROM 11 FOR 2 )||':'||SUBSTRING ( t.thetime FROM 13 FOR 2 )||'.00'
) AS TIMESTAMP)
Then I tried to include it in int using this technique
CAST(cast(
(SUBSTRING ( t.thetime FROM 5 FOR 2 )||'/'||SUBSTRING ( t.thetime FROM 7 FOR 2 )||'/'||SUBSTRING ( t.thetime FROM 1 FOR 4 )||' '|| SUBSTRING ( t.thetime FROM 9 FOR 2 )||':'||SUBSTRING ( t.thetime FROM 11 FOR 2 )||':'||SUBSTRING ( t.thetime FROM 13 FOR 2 )||'.00'
) AS TIMESTAMP)
-cast('01/01/1970 00:00:00' as timestamp) as BIGINT) as TIMESTAMP_INT
I get an integer, but it looks like the return value is the number of days or something like that.
eg. 01/08/2015, 16: 33: 01.114 becomes 16444
Any suggestions why this is happening or is there another way to do this?
I am using Firebird version 2.5
Thanks in advance
PS:
SELECT
CAST(cast(
(SUBSTRING ( '20140108154821' FROM 5 FOR 2 )||'/'||SUBSTRING ( '20140108154821' FROM 7 FOR 2 )||'/'||SUBSTRING ( '20140108154821' FROM 1 FOR 4 )||' '
||
SUBSTRING ( '20140108154821' FROM 9 FOR 2 )||':'||SUBSTRING ( '20140108154821' FROM 11 FOR 2 )||':'||SUBSTRING ( '20140108154821' FROM 13 FOR 2 )||'.00'
) AS TIMESTAMP)
-cast('01/01/1970 00:00:00' as timestamp) as BIGINT)
from sometable
;