<?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 Re: How to extract the date and time from a single column in a CSV file as separate fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218651#M64255</link>
    <description>&lt;P&gt;No problem, Woodcock.  I was just trying to be helpful with a solution which was already on the right track.  I'll just compile all of my ideas and corrections to your solution into my own solution.  I did not intend to "wander" to topics that you were not interested in discussing.  I do think that they are fully relevant to the question, though.&lt;/P&gt;

&lt;P&gt;PS: I was not aware that users could delete each other's comments.  I've never done that before or seen that option.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Sep 2015 14:28:37 GMT</pubDate>
    <dc:creator>landen99</dc:creator>
    <dc:date>2015-09-11T14:28:37Z</dc:date>
    <item>
      <title>How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218638#M64242</link>
      <description>&lt;P&gt;I have a CSV file with headers which have date and time stamp fields in a single column. I want to extract date and time as separate fields. e.g. on 1st row of dataset the DeclaredDate is "26/12/2008 10:30" I want to extract fields DeclareDate as 26/12/2008 in date format and 10:30 as DeclareTime in time format.&lt;/P&gt;

&lt;P&gt;If I import data using default CSV input type, the DeclareDate is extracted as timestamp for the event. However, I want both DeclaredDate as well as RevokedDate to be extracted in time format..&lt;/P&gt;

&lt;P&gt;Can someone give me some clue? I do not have background in regex.&lt;/P&gt;

&lt;P&gt;Sample data below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Id,Name,DeclaredDate,RevokedDate,RegionId,LgaId,Area,AgencyId,ReferenceNo
1,Mt Mologone S44,26/12/2008 10:30,29/12/2008 12:00,4,800,Bland District,NULL,NULL
2,Gulp Road,6/01/2009 15:00,18/01/2009 20:00,1,8350,"Wingecarribee District, nm",NULL,NULL
3,Beaumont,15/01/2009 14:00,16/01/2009 17:00,1,4000,Hornsby Local Goverment Area,NULL,NULL
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2015 12:43:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218638#M64242</guid>
      <dc:creator>ashabc</dc:creator>
      <dc:date>2015-09-10T12:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218639#M64243</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=DeclaredDate "(?&amp;lt;DeclareDate&amp;gt;\S+)\s+(?&amp;lt;DeclareTime&amp;gt;.*)" | rex field=RevokedDate "(?&amp;lt;RevokeDate&amp;gt;\S+)\s+(?&amp;lt;RevokeTime&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2015 14:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218639#M64243</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-10T14:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218640#M64244</link>
      <description>&lt;P&gt;you don't need "[" or "]".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\S+ works just as well by itself
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:14:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218640#M64244</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-10T17:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218641#M64245</link>
      <description>&lt;P&gt;True.  I will update answer and delete comments.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:15:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218641#M64245</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-10T17:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218642#M64246</link>
      <description>&lt;P&gt;Otherwise, a very elegant answer, I must say.&lt;/P&gt;

&lt;P&gt;I considered giving the eval strftime, and convert or fieldformat strptime approach instead of this one based on rex, but the author never mentioned the need for sorting or filtering the time fields or formatting it from Unix time to various formats or between different time zones, so I feel your rex answer meets the question perfectly.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:33:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218642#M64246</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-10T17:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218643#M64247</link>
      <description>&lt;P&gt;Thanks Woodcock. It certainly works.&lt;BR /&gt;
One other question in relation to this. If I now want the duration between DeclareDate and RevokeDate, how can I get that. I tried the example in the url below, but seems not working.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/39463/calculate-time-difference-between-2-fields-sum-and-group-by-month.html"&gt;http://answers.splunk.com/answers/39463/calculate-time-difference-between-2-fields-sum-and-group-by-month.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I tried this:&lt;/P&gt;

&lt;P&gt;| convert timeformat="%d/%m/%yT%H:%M" mktime(RevokedDate) mktime(DeclaredDate) | eval duration=RevokedDate-DeclaredDate&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 23:04:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218643#M64247</guid>
      <dc:creator>ashabc</dc:creator>
      <dc:date>2015-09-10T23:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218644#M64248</link>
      <description>&lt;P&gt;This is where you do my solution with eval strftime, strptime, subtraction and convert duration.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 01:02:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218644#M64248</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-11T01:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218645#M64249</link>
      <description>&lt;P&gt;Oh, and time zones may be a factor, because it is going to Unix time to be subtracted. &lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 01:04:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218645#M64249</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-11T01:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218646#M64250</link>
      <description>&lt;P&gt;For duration TZ should not be a factor because both times should be the same TZ and we don't care what it is because we are subtracting them; do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=DeclaredDate "(?&amp;lt;DeclareDate&amp;gt;\S+)\s+(?&amp;lt;DeclareTime&amp;gt;.*)" | rex field=RevokedDate "(?&amp;lt;RevokeDate&amp;gt;\S+)\s+(?&amp;lt;RevokeTime&amp;gt;.*)" | DeclaredDateEpoch=strptime(DeclaredDate, "%m/%d/%Y %H:%M") | RevokedDateEpoch=strptime(RevokedDate, "%m/%d/%Y %H:%M") | durationSeconds = RevokedDateEpoch - DeclaredDateEpoch
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2015 03:36:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218646#M64250</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-11T03:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218647#M64251</link>
      <description>&lt;P&gt;You Rex date and time separately, so they will not work. Also, the timezones may not be the same, as in the case with bit9 source. Lastly, duration in sec can be made pretty with tostring(sec, "duration").&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 10:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218647#M64251</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-11T10:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218648#M64252</link>
      <description>&lt;P&gt;He asked for 2 things: to separate the TimeDates and to calculate the difference.  My answer is in 2 parts that both use the original field.  Your comment about &lt;CODE&gt;tostring&lt;/CODE&gt; is fair, and I thought of it, but this Q&amp;amp;A has been wondering very much so I decided to stick to the main path.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 14:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218648#M64252</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-11T14:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218649#M64253</link>
      <description>&lt;P&gt;@landen99, I encountered a bug editing the comments in this post (when deleting a duplicate comment of yours) and it deleted the last few comments of yours on accident.  I am working to have it restored.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 14:22:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218649#M64253</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-09-11T14:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218650#M64254</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| rex field=DeclaredDate "(?&amp;lt;DeclareDate&amp;gt;\S+)\s+(?&amp;lt;DeclareTime&amp;gt;.*)" | rex field=RevokedDate "(?&amp;lt;RevokeDate&amp;gt;\S+)\s+(?&amp;lt;RevokeTime&amp;gt;.*)" | eval DeclaredDate=DeclaredDate." GMT" | eval RevokedDate=RevokedDate." GMT" | eval DeclaredDateEpoch=strptime(DeclaredDate, "%m/%e/%Y %H:%M %Z") | eval RevokedDateEpoch=strptime(RevokedDate, "%m/%e/%Y %H:%M %Z") | eval duration_sec = RevokedDateEpoch - DeclaredDateEpoch | eval duration=tostring(durationSeconds,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Time zone is an integral part of creating epoch time.  "GMT" is replaced with the respective time zones.  The difference on times of the timezones will not care what the timezone is set to, but other operations will care.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 14:27:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218650#M64254</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-11T14:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218651#M64255</link>
      <description>&lt;P&gt;No problem, Woodcock.  I was just trying to be helpful with a solution which was already on the right track.  I'll just compile all of my ideas and corrections to your solution into my own solution.  I did not intend to "wander" to topics that you were not interested in discussing.  I do think that they are fully relevant to the question, though.&lt;/P&gt;

&lt;P&gt;PS: I was not aware that users could delete each other's comments.  I've never done that before or seen that option.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 14:28:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218651#M64255</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-09-11T14:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the date and time from a single column in a CSV file as separate fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218652#M64256</link>
      <description>&lt;P&gt;Thank you both Woddcock and Landen. Both works!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 21:10:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-date-and-time-from-a-single-column-in-a-CSV/m-p/218652#M64256</guid>
      <dc:creator>ashabc</dc:creator>
      <dc:date>2015-09-11T21:10:54Z</dc:date>
    </item>
  </channel>
</rss>

