Search code examples
sqltimestampapache-drill

How can I get total number of seconds from a timestamp in Apache Drill


I'm trying to covert a timestamp to seconds in apache drill and can only find functions to extract the number of seconds in a timestamp instead rather than the timestamp converted to seconds.

I'm doing this to get the difference between dates to calculate the time between them.

enter image description here


Solution

  • The answer was to convert the date to UNIX_TIMESTAMP.

    SELECT UNIX_TIMESTAMP('2015-05-29 08:18:53.0', 'yyyy-MM-dd HH:mm:ss.SSS') FROM (VALUES(1));
    
     +-------------+
     |   EXPR$0    |
     +-------------+
     | 1432912733  |
     +-------------+
    

    Apache Drill UNIX_TIMESTAMP