<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Why not from_unixtime() function handles an unix timestamp in milliseconds? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/63354#M72935</link>
    <description>&lt;P&gt;I believe the original reason that it took seconds was for compatibility with Mysql's similarly-named function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can convert a millisecond unix timestamp into an Impala timestamp more efficiently using integer division/mod and the "interval" operator as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[localhost:21000] &amp;gt; select cast(1513895588243 div 1000 as timestamp) + interval (1513895588243 % 1000) milliseconds;
+------------------------------------------------------------------------------------------+
| cast(1513895588243 div 1000 as timestamp) + interval (1513895588243 % 1000) milliseconds |
+------------------------------------------------------------------------------------------+
| 2017-12-21 22:33:08.243000000                                                            |
+------------------------------------------------------------------------------------------+
Fetched 1 row(s) in 0.01s&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Jan 2018 19:28:42 GMT</pubDate>
    <dc:creator>Tim Armstrong</dc:creator>
    <dc:date>2018-01-05T19:28:42Z</dc:date>
    <item>
      <title>Why not from_unixtime() function handles an unix timestamp in milliseconds?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/63182#M72934</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A column in my table has an unix time in milliseconds. When I am trying to use from_unixtime() it is returning me null. In the documentation its mentioned that from_unixtime() handles only unix time in seconds. Any specific problem handling milliseconds?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select from_unixtime(1513895588243,"yyyy-MM-dd HH:mm:ss.SSSSSS");&lt;BR /&gt;&lt;BR /&gt;Result&amp;gt; &lt;SPAN&gt;from_unixtime(&lt;/SPAN&gt;1513895588243&lt;SPAN&gt;, 'yyyy-mm-dd hh:mm:ss.ssssss')&lt;/SPAN&gt;&lt;BR /&gt; NULL&lt;/PRE&gt;&lt;P&gt;I am expecting '&lt;SPAN&gt;2017-12-21&amp;nbsp;22:33:08.243000000&lt;/SPAN&gt;'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote below query which would give me the result as expected above,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select 1513895588243, cast(concat(cast(from_unixtime(CAST(1513895588243/1000 as BIGINT), 'yyyy-MM-dd HH:mm:ss') as String),'.',substr(cast(1513895588243 as String), 11, 3)) as timestamp);&lt;BR /&gt;&lt;BR /&gt;Result:&lt;BR /&gt;&lt;SPAN&gt;1513895588243      2017-12-21&amp;nbsp;22:33:08.243000000&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, the above query is not an efficient way.&amp;nbsp;Is there any efficient workaround for this?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 16 Sep 2022 12:41:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/63182#M72934</guid>
      <dc:creator>munna143</dc:creator>
      <dc:date>2022-09-16T12:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why not from_unixtime() function handles an unix timestamp in milliseconds?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/63354#M72935</link>
      <description>&lt;P&gt;I believe the original reason that it took seconds was for compatibility with Mysql's similarly-named function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can convert a millisecond unix timestamp into an Impala timestamp more efficiently using integer division/mod and the "interval" operator as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[localhost:21000] &amp;gt; select cast(1513895588243 div 1000 as timestamp) + interval (1513895588243 % 1000) milliseconds;
+------------------------------------------------------------------------------------------+
| cast(1513895588243 div 1000 as timestamp) + interval (1513895588243 % 1000) milliseconds |
+------------------------------------------------------------------------------------------+
| 2017-12-21 22:33:08.243000000                                                            |
+------------------------------------------------------------------------------------------+
Fetched 1 row(s) in 0.01s&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 19:28:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/63354#M72935</guid>
      <dc:creator>Tim Armstrong</dc:creator>
      <dc:date>2018-01-05T19:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why not from_unixtime() function handles an unix timestamp in milliseconds?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/83904#M72936</link>
      <description>&lt;P&gt;The same can be peformed in hive using concat_ws('.',from_unixtime(cast(epochmillis/1000 as BIGINT),'yyyy-MM-dd HH:mm:ss'),cast(floor(epochmillis % 1000) as STRING)) to get the timestamp with milliseconds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this efficient way of doing it ?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 18:07:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Why-not-from-unixtime-function-handles-an-unix-timestamp-in/m-p/83904#M72936</guid>
      <dc:creator>bigdata-beast</dc:creator>
      <dc:date>2018-12-14T18:07:00Z</dc:date>
    </item>
  </channel>
</rss>

