<?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: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121408#M84167</link>
    <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;@Sooraj Antony&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;&lt;/A&gt;@&lt;A href="https://community.hortonworks.com/users/235/bpreachuk.html"&gt;bpreachuk&lt;/A&gt; response is appropriate. Please accept or vote to appreciate the effort.&lt;/P&gt;</description>
    <pubDate>Sat, 27 Aug 2016 01:04:33 GMT</pubDate>
    <dc:creator>cstanca</dc:creator>
    <dc:date>2016-08-27T01:04:33Z</dc:date>
    <item>
      <title>UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121405#M84164</link>
      <description>&lt;P&gt;
	The below query fetches UNIX_TIMESTAMP of the same time string but one of them is hardcoded and other fetched from a table.&lt;/P&gt;
&lt;PRE&gt;select distinct UNIX_TIMESTAMP(TIME, 'yyyy-mm-dd HH:mm:ss'),UNIX_TIMESTAMP('2015-08-22 00:00:32', 'yyyy-mm-dd HH:mm:ss') from clicks where time='2015-08-22 00:00:32';
&lt;/PRE&gt;&lt;P&gt;
	Both the fields are supposed to give the same result as the time string is same. But the output is,&lt;/P&gt;&lt;P&gt;
	_c0                                 _c1&lt;/P&gt;&lt;P&gt;	1440201632       1421884832&lt;/P&gt;&lt;P&gt;Is there any reason why it differs? Is there any workaround?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 20:16:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121405#M84164</guid>
      <dc:creator>sooraj_antony</dc:creator>
      <dc:date>2016-08-26T20:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121406#M84165</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/1213/soorajantony.html" nodeid="1213"&gt;@Sooraj Antony&lt;/A&gt;.  Here is the issue  - your format string is incorrect.  Be careful - the format string is CaSe SenSiTive.  &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;  &lt;/P&gt;&lt;P&gt;Here is documentation:  &lt;A href="http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html" target="_blank"&gt;http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is an example - note the case sensitivity in the format: &lt;/P&gt;&lt;PRE&gt;select  
     UNIX_TIMESTAMP('2015-08-22 00:00:32', 'yyyy-MM-dd HH:mm:ss'),
     from_unixtime(1440201632, 'yyyy-MM-dd HH:mm:ss'),
     from_unixtime(1421884832, 'yyyy-MM-dd HH:mm:ss')
from sample_07 
limit 1; &lt;/PRE&gt;&lt;P&gt;Results: &lt;/P&gt;&lt;PRE&gt;col1       col2                col3 
1440201632 2015-08-22 00:00:32 2015-01-22 00:00:32&lt;/PRE&gt;&lt;P&gt;I hope this helps.  &lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2016 00:42:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121406#M84165</guid>
      <dc:creator>bpreachuk</dc:creator>
      <dc:date>2016-08-27T00:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121407#M84166</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;@Sooraj Antony&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;&lt;/A&gt;m is used for minute&lt;/P&gt;&lt;P&gt;M is used for month&lt;/P&gt;&lt;P&gt;In your case should be YYYY-MM-DD hh:mm:ss or yyyy-MM-dd hh:mm:ss&lt;/P&gt;&lt;P&gt;select UNIX_TIMESTAMP('2000-01-01 10:20:30','yyyy-MM-dd hh:mm:ss');&lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2016 00:59:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121407#M84166</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-08-27T00:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121408#M84167</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;@Sooraj Antony&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/1213/soorajantony.html"&gt;&lt;/A&gt;@&lt;A href="https://community.hortonworks.com/users/235/bpreachuk.html"&gt;bpreachuk&lt;/A&gt; response is appropriate. Please accept or vote to appreciate the effort.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2016 01:04:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121408#M84167</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-08-27T01:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121409#M84168</link>
      <description>&lt;P&gt;Thats perfect!!! But still just curious to know how it works fine when the string is taken from a table and "mm" in format.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2016 04:06:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121409#M84168</guid>
      <dc:creator>sooraj_antony</dc:creator>
      <dc:date>2016-08-28T04:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: UNIX_TIMESTAMP function returns different values when provided with hardcoded time and the one fetched from table</title>
      <link>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121410#M84169</link>
      <description>&lt;P&gt;That's the interesting part - it actually wasn't working correctly.  It was just hard to see the issue without doing the corresponding from_unixtime call.  &lt;/P&gt;&lt;P&gt;When you were doing the UNIX_TIMESTAMP call it was using '00' as the month, since the format string was using 'minutes' instead of 'months'.  For whatever reason, the UNIX_TIMESTAMP function returns a timestamp value when the format string causes you to pass in invalid data like Month = '00'.  In my opinion it should fail instead of returning invalid data like that.  &lt;/P&gt;&lt;P&gt;Check out this query - the first 2 columns use the correct data format string, while the second 2 columns use the invalid date format string (minutes instead of months): &lt;/P&gt;&lt;PRE&gt;select  
     from_unixtime(1440201632, 'yyyy-MM-dd HH:mm:ss') as `good_date1`,
     from_unixtime(1421884832, 'yyyy-MM-dd HH:mm:ss') as `good_date2`,
     from_unixtime(1440201632, 'yyyy-mm-dd HH:mm:ss') as `bad_date1`,
     from_unixtime(1421884832, 'yyyy-mm-dd HH:mm:ss') as `bad_date2`
from sample_07 limit 1; &lt;/PRE&gt;&lt;P&gt;and results: &lt;/P&gt;&lt;PRE&gt;good_date1           good_date2           bad_date1            bad_date2
2015-08-22 00:00:32  2015-01-22 00:00:32  2015-00-22 00:00:32  2015-00-22 00:00:32&lt;/PRE&gt;&lt;P&gt;Notice that the bad dates have zeros in their month field instead of 8 and 1 respectively.  &lt;/P&gt;&lt;P&gt;Hope this helps.  &lt;/P&gt;</description>
      <pubDate>Sun, 28 Aug 2016 21:22:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/UNIX-TIMESTAMP-function-returns-different-values-when/m-p/121410#M84169</guid>
      <dc:creator>bpreachuk</dc:creator>
      <dc:date>2016-08-28T21:22:01Z</dc:date>
    </item>
  </channel>
</rss>

