title: Following date conversion query in Snowflake is not working
body: <p>A varchar column in a table contains dates in '05/13/2019 20:48:13 PM' format. It can contain either a single date or many dates concatenated with pipe |. I use this query to get the very first one and try to convert it to timestamp.</p>
  
  <pre><code>Select (CASE WHEN  charindex('AM', COMPL_DATE)&gt;=1 OR   charindex('PM', COMPL_DATE) &gt;= 1
          THEN TO_TIMESTAMP ( SPLIT_PART( COMPL_DATE, '|' , 1), 'MM/DD/YYYY hh24:mi:ss AM')
          ELSE TO_TIMESTAMP ( SPLIT_PART( COMPL_DATE, '|' , 1), 'MM/DD/YYYY hh:mi:ss')
       END 
      ) from some_table.
  </code></pre>
  
  <p>I get this error
  <em>Can't parse '03/23/2019 20:56:22 PM' as timestamp with format 'MM/DD/YYYY hh24:mi:ss AM'</em>. </p>
  
  <p>It is not that it fails for all the rows. There are some rows for which it fails.
  However when I use this data to run separately, like this - </p>
  
  <pre><code>with tab as ( select  '03/23/2019 20:56:22 PM' COMPL_DATE from dual )
  SELECT 
    (CASE WHEN  charindex('AM',COMPL_DATE)&gt;=1 OR   charindex('PM',COMPL_DATE) &gt;= 1
          THEN  TO_TIMESTAMP ( SPLIT_PART( COMPL_DATE, '|' , 1), 'MM/DD/YYYY hh:mi:ss AM')
          ELSE  TO_TIMESTAMP ( SPLIT_PART( COMPL_DATE, '|' , 1), 'MM/DD/YYYY hh24:mi:ss')
     END 
     ) result
  FROM tab ;
  </code></pre>
  
  <p>It works fine.</p>
  
  <p>Any help is appreciated.</p>