<?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>topic Format Date in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Format-Date/m-p/2232478#M22425</link>
    <description>&lt;P&gt;I am passing a date value to a global variable and then trying to print it to the screen using tJavaRow:&lt;/P&gt;
&lt;P&gt;System.out.println(globalMap.get("MaxInsertDateTime"));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this prints fine - here is the output:&lt;/P&gt;
&lt;P&gt;2019-07-15T03:46:02&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However what I would like to do is format the value to "YYYY-MM-DD" format. I tried multiple different ways to do it but no luck so far:&lt;/P&gt;
&lt;P&gt;System.out.println(TalendDate.formatDate("YYYY-MM-DD",(globalMap.get("MaxInsertDateTime"))));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error:&lt;/P&gt;
&lt;P&gt;Detail Message: The method formatDate(String, Date) in the type TalendDate is not applicable for the arguments (String, Object)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also tried this:&lt;/P&gt;
&lt;P&gt;System.out.println((String)globalMap.get("MaxInsertDateTime"));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error:&lt;/P&gt;
&lt;P&gt;java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to format the date as "YYYY-MM-DD" and then use it later in tMSSQLInput component in a where condition.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 05:15:59 GMT</pubDate>
    <dc:creator>talendstar</dc:creator>
    <dc:date>2024-11-16T05:15:59Z</dc:date>
    <item>
      <title>Format Date</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Format-Date/m-p/2232478#M22425</link>
      <description>&lt;P&gt;I am passing a date value to a global variable and then trying to print it to the screen using tJavaRow:&lt;/P&gt;
&lt;P&gt;System.out.println(globalMap.get("MaxInsertDateTime"));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this prints fine - here is the output:&lt;/P&gt;
&lt;P&gt;2019-07-15T03:46:02&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However what I would like to do is format the value to "YYYY-MM-DD" format. I tried multiple different ways to do it but no luck so far:&lt;/P&gt;
&lt;P&gt;System.out.println(TalendDate.formatDate("YYYY-MM-DD",(globalMap.get("MaxInsertDateTime"))));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error:&lt;/P&gt;
&lt;P&gt;Detail Message: The method formatDate(String, Date) in the type TalendDate is not applicable for the arguments (String, Object)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also tried this:&lt;/P&gt;
&lt;P&gt;System.out.println((String)globalMap.get("MaxInsertDateTime"));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error:&lt;/P&gt;
&lt;P&gt;java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to format the date as "YYYY-MM-DD" and then use it later in tMSSQLInput component in a where condition.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 05:15:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Format-Date/m-p/2232478#M22425</guid>
      <dc:creator>talendstar</dc:creator>
      <dc:date>2024-11-16T05:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Format Date</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Format-Date/m-p/2232479#M22426</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The message is telling you what's wrong :&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;The method formatDate(String, Date) in the type TalendDate is not applicable for the arguments (String, Object)&lt;/PRE&gt; 
&lt;P&gt;Java doesn't know that your&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;globalMap.get("MaxInsertDateTime")&lt;/STRONG&gt; object is actually a date, so it takes it as an Object and cannot use formatDate on an Object.&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;You have to explicitly tell that&amp;nbsp;&lt;STRONG&gt;globalMap.get("MaxInsertDateTime")&lt;/STRONG&gt; is a Date (assuming it &lt;STRONG&gt;*is*&lt;/STRONG&gt; a date of course).&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;SPAN&gt;If you setup your global variable correctly, this should work :&lt;/SPAN&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;System.out.println(TalendDate.formatDate("yyyy-MM-dd",&lt;STRONG&gt;(Date)&lt;/STRONG&gt;globalMap.get("MaxInsertDateTime")));&lt;/PRE&gt; 
&lt;P&gt;btw: Talend corrects the misuse of upper/lower case in the date format but I strongly suggest you to use the proper case (see &lt;A href="https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html" target="_self" rel="nofollow noopener noreferrer"&gt;SimpleDateFormat&lt;/A&gt; for the detail)&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 17:22:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Format-Date/m-p/2232479#M22426</guid>
      <dc:creator>lennelei</dc:creator>
      <dc:date>2019-07-16T17:22:15Z</dc:date>
    </item>
  </channel>
</rss>

