<?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 change string from csv file to date format for proper sorting in search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192624#M55406</link>
    <description>&lt;P&gt;Somewhere in your search string, add the following clause:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;convert timeformat="%m/%d/%Y" mktime(date) as numdate&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;That will create a new field &lt;CODE&gt;numdate&lt;/CODE&gt; containing the epoch numerical representation of your &lt;CODE&gt;date&lt;/CODE&gt; field. You can then sort on &lt;CODE&gt;numdate&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Read more about &lt;CODE&gt;convert&lt;/CODE&gt; here:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/Convert&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Aug 2014 20:35:53 GMT</pubDate>
    <dc:creator>aweitzman</dc:creator>
    <dc:date>2014-08-22T20:35:53Z</dc:date>
    <item>
      <title>How to change string from csv file to date format for proper sorting in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192622#M55404</link>
      <description>&lt;P&gt;I have data that was imported from a .csv file. One of the field in the .csv file is called "date".  However, when Splunk imports that field the data is a string in the format 8/22/2014.  I would like to sort the data by this "date" field but, Splunk does not sort it correctly because it sees the data as a string and sorts based on left to right.  &lt;/P&gt;

&lt;P&gt;How can I make it so that I can sort on the "date" data as if it was an actual date?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 20:03:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192622#M55404</guid>
      <dc:creator>jwolach2</dc:creator>
      <dc:date>2014-08-22T20:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to change string from csv file to date format for proper sorting in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192623#M55405</link>
      <description>&lt;P&gt;You can try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search to get data from csv | eval date=strptime(date,"%m/%d/%Y") | sort 0 date
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Aug 2014 20:33:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192623#M55405</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-08-22T20:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to change string from csv file to date format for proper sorting in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192624#M55406</link>
      <description>&lt;P&gt;Somewhere in your search string, add the following clause:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;convert timeformat="%m/%d/%Y" mktime(date) as numdate&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;That will create a new field &lt;CODE&gt;numdate&lt;/CODE&gt; containing the epoch numerical representation of your &lt;CODE&gt;date&lt;/CODE&gt; field. You can then sort on &lt;CODE&gt;numdate&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Read more about &lt;CODE&gt;convert&lt;/CODE&gt; here:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/Convert&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 20:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192624#M55406</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-08-22T20:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to change string from csv file to date format for proper sorting in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192625#M55407</link>
      <description>&lt;P&gt;Great!!!  Thank you very much!  So here's what I now have as my search statement.&lt;/P&gt;

&lt;P&gt;sourcetype=csv | eval date=strptime(date,"%m/%d/%Y") | eval reformatted_date=strftime(date,"%m/%d/%Y") | sort 0 date AND inv | table reformatted_date inv customer item vendor | where reformatted_date &amp;lt; "01/31/14"&lt;/P&gt;

&lt;P&gt;Now, I would like to select a date range to be displayed.  How can I do that with the epoch numerical data?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:23:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192625#M55407</guid>
      <dc:creator>jwolach2</dc:creator>
      <dc:date>2020-09-28T17:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to change string from csv file to date format for proper sorting in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192626#M55408</link>
      <description>&lt;P&gt;Got it, I think.&lt;/P&gt;

&lt;P&gt;sourcetype=csv | eval date=strptime(date,"%m/%d/%Y") | eval reformatted_date=strftime(date,"%m/%d/%Y") | sort 0 date AND inv | table date reformatted_date inv customer item vendor description | where (date &amp;gt; strptime("05/31/2013","%m/%d/%Y") AND date &amp;lt; strptime("07/01/2013","%m/%d/%Y"))&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:23:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-change-string-from-csv-file-to-date-format-for-proper/m-p/192626#M55408</guid>
      <dc:creator>jwolach2</dc:creator>
      <dc:date>2020-09-28T17:23:41Z</dc:date>
    </item>
  </channel>
</rss>

