Timestamp to epoch conversion in teradata -


i have timestamp column in teradata table. want convert timestamp epoch value. can shed light on how this.

this sql udf wrote few years ago.

if don't have access rights create function, mighty ask dab or cut & paste calculation.

/********** converting timestamp unix/posix/epoch time  unix time: number of seconds since 1970-01-01 00:00:00 utc not counting leap seconds (currently 34 in 2010)  maximum range of timestamps based on range of integers: 1901-12-13 20:45:52 (-2147483648) 2038-01-19 03:14:07 (2147483647)  change bigint cover full teradata date range  20101211 initial version - dieter noeth **********/ replace function timestamp_to_unixtime (ts timestamp(6)) returns int language sql contains sql deterministic sql security definer collation invoker inline type 1 return  (cast(ts date) - date '1970-01-01') * 86400 + (extract(hour ts) * 3600) + (extract(minute ts) * 60) + (extract(second ts)) ; 

reversing calculation:

/********** converting unix/posix/epoch time timestamp   unix time: number of seconds since 1970-01-01 00:00:00 utc not counting leap seconds (currently 34 in 2010)  working negative numbers. maximum range of timestamps based on range of integers: 1901-12-13 20:45:52 (-2147483648) 2038-01-19 03:14:07 (2147483647)  change bigint cover full teradata date range  20101211 initial version - dieter noeth **********/  replace function unixtime_to_timestamp (unixtime int) returns timestamp(0) language sql contains sql deterministic sql security definer collation invoker inline type 1 return  cast(date '1970-01-01' + (unixtime / 86400) timestamp(0)) + ((unixtime mod 86400) * interval '00:00:01' hour second) ; 

it's easier in td14 using to_timestamp(unixtime), restricted integer range.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -