<?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 NiFi: Converting a datetime field (CSV to DB) in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228378#M190238</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;With NiFi, I'm picking up a CSV file whose records have a bit of a silly timestamp format: MM-dd-yyyy HH:mm:ss. I want to convert this into yyyy-MM-dd HH:mm:ss before attempting to insert this into a SQL server datetime field.&lt;/P&gt;&lt;P&gt;To do this, I'm trying the ConvertRecord processor, with a CSVReader and currently a JSONRecordSetWriter (convenient since it allows me easily read the resulting data. An example CSV is:&lt;/P&gt;&lt;PRE&gt;id;timestamp
1;11-12-2016 9:38:13
2;12-12-2016 9:38:14
3;12-21-2016 9:38:15
&lt;/PRE&gt;&lt;P&gt;For the CSVReader, my schema text is:&lt;/P&gt;&lt;PRE&gt;{    
"type": "record",
    "name": "testdata",
    "fields": [
		{
            "name": "id",
            "type": "int"
        },
        {
            "name": "timestamp",
            "type": {"type":"string","logicalType":"timestamp"}
        }
    ]
}
&lt;/PRE&gt;&lt;P&gt;I've set the property Timestamp format to MM-dd-yyyy HH:mm:ss.&lt;/P&gt;&lt;P&gt;I'm using the same schema text for the JSONRecordSetWriter and have the Timestamp format set to yyyy--MM-dd HH:mm:ss.&lt;/P&gt;&lt;P&gt;I'm expecting this to achieve the datetime conversion that I need to do, but in the resulting JSON my datetime field is exactly the same.&lt;/P&gt;&lt;P&gt;Attached you'll find and XML template that demos this.&lt;/P&gt;&lt;P&gt;Am I going about this the wrong way and completely misunderstanding what ConvertRecord does? Am I missing something?&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/85786-datetime-format-conversion.xml"&gt;datetime-format-conversion.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: I'm still interested to hear your take on this, but as it so often goes I solved the problem a little while after I posted this question. I'm using UpdateRecord and doing:&lt;/P&gt;&lt;PRE&gt;${field.value:toDate('MM-dd-yyyy HH:mm:ss'):format('yyyy-MM-dd HH:mm:ss')}&lt;/PRE&gt;&lt;P&gt;That works for me.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 21:56:10 GMT</pubDate>
    <dc:creator>waltervos</dc:creator>
    <dc:date>2018-08-29T21:56:10Z</dc:date>
    <item>
      <title>NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228378#M190238</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;With NiFi, I'm picking up a CSV file whose records have a bit of a silly timestamp format: MM-dd-yyyy HH:mm:ss. I want to convert this into yyyy-MM-dd HH:mm:ss before attempting to insert this into a SQL server datetime field.&lt;/P&gt;&lt;P&gt;To do this, I'm trying the ConvertRecord processor, with a CSVReader and currently a JSONRecordSetWriter (convenient since it allows me easily read the resulting data. An example CSV is:&lt;/P&gt;&lt;PRE&gt;id;timestamp
1;11-12-2016 9:38:13
2;12-12-2016 9:38:14
3;12-21-2016 9:38:15
&lt;/PRE&gt;&lt;P&gt;For the CSVReader, my schema text is:&lt;/P&gt;&lt;PRE&gt;{    
"type": "record",
    "name": "testdata",
    "fields": [
		{
            "name": "id",
            "type": "int"
        },
        {
            "name": "timestamp",
            "type": {"type":"string","logicalType":"timestamp"}
        }
    ]
}
&lt;/PRE&gt;&lt;P&gt;I've set the property Timestamp format to MM-dd-yyyy HH:mm:ss.&lt;/P&gt;&lt;P&gt;I'm using the same schema text for the JSONRecordSetWriter and have the Timestamp format set to yyyy--MM-dd HH:mm:ss.&lt;/P&gt;&lt;P&gt;I'm expecting this to achieve the datetime conversion that I need to do, but in the resulting JSON my datetime field is exactly the same.&lt;/P&gt;&lt;P&gt;Attached you'll find and XML template that demos this.&lt;/P&gt;&lt;P&gt;Am I going about this the wrong way and completely misunderstanding what ConvertRecord does? Am I missing something?&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/85786-datetime-format-conversion.xml"&gt;datetime-format-conversion.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: I'm still interested to hear your take on this, but as it so often goes I solved the problem a little while after I posted this question. I'm using UpdateRecord and doing:&lt;/P&gt;&lt;PRE&gt;${field.value:toDate('MM-dd-yyyy HH:mm:ss'):format('yyyy-MM-dd HH:mm:ss')}&lt;/PRE&gt;&lt;P&gt;That works for me.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 21:56:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228378#M190238</guid>
      <dc:creator>waltervos</dc:creator>
      <dc:date>2018-08-29T21:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228379#M190239</link>
      <description>&lt;P&gt;This is the proper method...  Good job!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 00:23:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228379#M190239</guid>
      <dc:creator>stevenmatison</dc:creator>
      <dc:date>2018-08-30T00:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228380#M190240</link>
      <description>&lt;P&gt;Thanks! For the next person trying to accomplish something like this, I've attached another xml template that demonstrates this functionality: &lt;A href="https://community.cloudera.com/legacyfs/online/attachments/88398-updaterecord-datetime-conversion.xml"&gt;updaterecord-datetime-conversion.xml&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 13:30:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228380#M190240</guid>
      <dc:creator>waltervos</dc:creator>
      <dc:date>2018-08-30T13:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228381#M190241</link>
      <description>&lt;P&gt;The next thing you can do is write your own answer, then accept it.  I believe you will get some profile badges for doing that.   &lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 18:20:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228381#M190241</guid>
      <dc:creator>stevenmatison</dc:creator>
      <dc:date>2018-08-30T18:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228382#M190242</link>
      <description>&lt;P&gt;Per &lt;A rel="user" href="https://community.cloudera.com/users/87347/stevenmatison.html" nodeid="87347"&gt;@Steven Matison&lt;/A&gt;'s suggestion, I'm posting the solution to the problem I was facing as an answer:&lt;/P&gt;&lt;P&gt;I was using the wrong processor. It turns out the UpdateRecord processor is a good fit for this. I'm updating the field in question with the following expression language command:&lt;/P&gt;&lt;PRE&gt;${field.value:toDate('MM-dd-yyyy HH:mm:ss'):format('yyyy-MM-dd HH:mm:ss')}&lt;/PRE&gt;&lt;P&gt;Here's an XML template that demonstrates this functionality: &lt;A href="https://community.cloudera.com/legacyfs/online/attachments/87495-updaterecord-datetime-conversion.xml"&gt;updaterecord-datetime-conversion.xml&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 14:13:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228382#M190242</guid>
      <dc:creator>waltervos</dc:creator>
      <dc:date>2018-08-31T14:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228383#M190243</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/91490/waltervos.html" nodeid="91490"&gt;@Walter Vos &lt;/A&gt; Thanks, saved me from loosing my mind!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Jul 2019 20:34:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/228383#M190243</guid>
      <dc:creator>justenji</dc:creator>
      <dc:date>2019-07-10T20:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/297367#M218664</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;My input data is a JSON which has value like "Thu Jun 04 11:54:54 UTC 2020". How should I convert this in AvroSchema "YYYY-MM-DD hh:mm:ss".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2020 11:58:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/297367#M218664</guid>
      <dc:creator>skiganesh</dc:creator>
      <dc:date>2020-06-04T11:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298161#M219026</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61747"&gt;@waltervos&lt;/a&gt;&amp;nbsp;, I need to achieve this data conversion in updateAttribute processor. Below are my configuration in updateAttribure.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PropertyName:&lt;/STRONG&gt;&amp;nbsp;&lt;SPAN&gt;created_date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Value as :&lt;/STRONG&gt; ${created_date.value:toDate("EEE MMM dd HH:mm:ss z yyyy"):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After updateAttribute I have AttributesToJSON processor -&amp;gt; PutDatabaseRecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not getting the converted value after updateAttribute or&amp;nbsp;AttributesToJSON. Please suggest how to get the updated value in&amp;nbsp;PutDatabaseRecord. Input JSON attached.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="InputJson.png" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/28005iB0CDCB7677178724/image-size/large?v=v2&amp;amp;px=999" role="button" title="InputJson.png" alt="InputJson.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 08:38:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298161#M219026</guid>
      <dc:creator>skiganesh</dc:creator>
      <dc:date>2020-06-17T08:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298162#M219027</link>
      <description>&lt;P&gt;Why do you have toNumber() in there,&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/69982"&gt;@skiganesh&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 08:45:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298162#M219027</guid>
      <dc:creator>waltervos</dc:creator>
      <dc:date>2020-06-17T08:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298166#M219028</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61747"&gt;@waltervos&lt;/a&gt;&amp;nbsp;, Yes, it worked without converting it to Number also, I was applying the solutions from another post.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 09:25:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298166#M219028</guid>
      <dc:creator>skiganesh</dc:creator>
      <dc:date>2020-06-17T09:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298184#M219030</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/61747"&gt;@waltervos&lt;/a&gt;&amp;nbsp;, I am not getting date converted in updateAttribute processor. Please suggest.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 10:26:45 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298184#M219030</guid>
      <dc:creator>skiganesh</dc:creator>
      <dc:date>2020-06-17T10:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: Converting a datetime field (CSV to DB)</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298321#M219103</link>
      <description>&lt;P&gt;"UpdateRecord" processor with below syntax resolved the issue.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;${field.value:toDate("EEE MMM dd HH:mm:ss z yyyy"):format("yyyy-MM-dd HH:mm:ss")}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 19 Jun 2020 18:26:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-Converting-a-datetime-field-CSV-to-DB/m-p/298321#M219103</guid>
      <dc:creator>skiganesh</dc:creator>
      <dc:date>2020-06-19T18:26:26Z</dc:date>
    </item>
  </channel>
</rss>

