<?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 Impala String Date - greater than or less than command to query tables in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80129#M83694</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a date which is stored as string and we would like to query it in Impala using greater than or less than functionality , however i am having no luck and when i play around unixtimestamp/timestamp&lt;/P&gt;&lt;P&gt;it returns as Null values.&lt;/P&gt;&lt;P&gt;e.g. select * from table T1 where orderdate is less than &amp;lt; 1/1/2001&lt;/P&gt;&lt;P&gt;order date is stored as string in T1 and doesnot have padded zeroes : 1/1/2001 (and not 01/01/2001)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;cast(unix_timestamp(`date`, "MM/dd/yyyy") as timestamp), `date`&amp;nbsp;FROM&amp;nbsp;T1 ;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result --&amp;nbsp; Null values for cast command&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT *&amp;nbsp;FROM T1&amp;nbsp;WHERE start = '"4/3/2015"' ;&lt;/P&gt;&lt;P&gt;Result - No data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SELECT *&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;FROM T1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WHERE start &amp;gt; "4/3/2015" ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Result - No data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 13:43:59 GMT</pubDate>
    <dc:creator>PD</dc:creator>
    <dc:date>2022-09-16T13:43:59Z</dc:date>
    <item>
      <title>Impala String Date - greater than or less than command to query tables</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80129#M83694</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a date which is stored as string and we would like to query it in Impala using greater than or less than functionality , however i am having no luck and when i play around unixtimestamp/timestamp&lt;/P&gt;&lt;P&gt;it returns as Null values.&lt;/P&gt;&lt;P&gt;e.g. select * from table T1 where orderdate is less than &amp;lt; 1/1/2001&lt;/P&gt;&lt;P&gt;order date is stored as string in T1 and doesnot have padded zeroes : 1/1/2001 (and not 01/01/2001)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;cast(unix_timestamp(`date`, "MM/dd/yyyy") as timestamp), `date`&amp;nbsp;FROM&amp;nbsp;T1 ;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result --&amp;nbsp; Null values for cast command&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT *&amp;nbsp;FROM T1&amp;nbsp;WHERE start = '"4/3/2015"' ;&lt;/P&gt;&lt;P&gt;Result - No data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SELECT *&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;FROM T1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WHERE start &amp;gt; "4/3/2015" ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Result - No data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:43:59 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80129#M83694</guid>
      <dc:creator>PD</dc:creator>
      <dc:date>2022-09-16T13:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Impala String Date - greater than or less than command to query tables</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80130#M83695</link>
      <description>&lt;P&gt;Hi, it is not so common to have a date in this format, but it is possible to convert it into timestamp in Impala.&lt;/P&gt;&lt;P&gt;Your approach was good, just used a wrong format:&lt;/P&gt;&lt;PRE&gt;&amp;gt; CORRECT FORMAT
[10.197.0.1:21000] &amp;gt; select *, cast( unix_timestamp(s, "M/d/yyyy") as timestamp ) from work.t;
+-----+------------+--------------------------------------------------+
| id  | s          | cast(unix_timestamp(s, 'm/d/yyyy') as timestamp) |
+-----+------------+--------------------------------------------------+
| 100 | 12/24/2018 | 2018-12-24 00:00:00                              |
| 200 | 3/24/2018  | 2018-03-24 00:00:00                              |
+-----+------------+--------------------------------------------------+
Fetched 2 row(s) in 0.33s

&amp;gt; THIS IS A WRONG FORMAT
[10.197.0.1:21000] &amp;gt; select *, cast( unix_timestamp(s, "MM/dd/yyyy") as timestamp ) from work.t;
+-----+------------+----------------------------------------------------+
| id  | s          | cast(unix_timestamp(s, 'mm/dd/yyyy') as timestamp) |
+-----+------------+----------------------------------------------------+
| 100 | 12/24/2018 | 2018-12-24 00:00:00                                |
| 200 | 3/24/2018  | NULL                                               |
+-----+------------+----------------------------------------------------+&lt;/PRE&gt;&lt;P&gt;Convert the string to a date and then you can use a correct where conditions.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 18:41:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80130#M83695</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2018-09-20T18:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Impala String Date - greater than or less than command to query tables</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80145#M83696</link>
      <description>&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; that resolved it for me.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 19:57:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-String-Date-greater-than-or-less-than-command-to/m-p/80145#M83696</guid>
      <dc:creator>PD</dc:creator>
      <dc:date>2018-09-20T19:57:23Z</dc:date>
    </item>
  </channel>
</rss>

