<?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 find the earliest date in a multivalue field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113319#M29805</link>
    <description>&lt;P&gt;Could you pls provide an example how your MV field looks like?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Nov 2014 22:32:19 GMT</pubDate>
    <dc:creator>musskopf</dc:creator>
    <dc:date>2014-11-05T22:32:19Z</dc:date>
    <item>
      <title>How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113318#M29804</link>
      <description>&lt;P&gt;I have a multivalue field which contains date strings. I would like to find the earliest one of the field and set a new variable to that value. Foreach seems to choke on multivalue fields. Any ideas would be grand.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 22:25:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113318#M29804</guid>
      <dc:creator>nfieglein</dc:creator>
      <dc:date>2014-11-05T22:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113319#M29805</link>
      <description>&lt;P&gt;Could you pls provide an example how your MV field looks like?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 22:32:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113319#M29805</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2014-11-05T22:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113320#M29806</link>
      <description>&lt;P&gt;LogEntry.Content.CommentSegmentGrp.CommentSegment{}.CommentDate                 &lt;/P&gt;

&lt;P&gt;Fri Oct 31 00:00:00 CDT 2014&lt;BR /&gt;&lt;BR /&gt;
                                                                                                                                                       Mon Oct 27 00:00:00 CDT 2014 &lt;BR /&gt;
                                                                                                                                                       Sat Nov 01 00:00:00 CDT 2014 &lt;BR /&gt;
                                                                                                                                                       Thu Oct 30 00:00:00 CDT 2014 &lt;BR /&gt;
                                                                                                                                                       Tue Oct 28 00:00:00 CDT 2014&lt;BR /&gt;
                                                                                                                                                       Wed Oct 29 00:00:00 CDT 2014 &lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 22:46:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113320#M29806</guid>
      <dc:creator>nfieglein</dc:creator>
      <dc:date>2014-11-05T22:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113321#M29807</link>
      <description>&lt;P&gt;Hi nfieglein,&lt;/P&gt;

&lt;P&gt;Here an approach might work...&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;the first 3 commands are just to generate a similar MV field you have&lt;/EM&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=0 end=1 | eval mv="Fri Oct 31 00:00:00 CDT 2014,Mon Oct 27 00:00:00 CDT 2014,Sat Nov 01 00:00:00 CDT 2014,Thu Oct 30 00:00:00 CDT 2014,Tue Oct 28 00:00:00 CDT 2014,Wed Oct 29 00:00:00 CDT 2014" | makemv delim="," mv
| eval datemv=strptime(mv,"%a %b %d %H:%M:%S CDT %Y")
| eval most_recent_seconds=max(datemv)
| eval most_recent_human=strftime(most_recent_seconds,"%a %b %d %H:%M:%S CDT %Y")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The idea was to first convert your date to seconds, and them select the most recent. After that you might wish to convert back to date format.&lt;/P&gt;

&lt;P&gt;If you're using Splunk 6.2 there is a new command named &lt;CODE&gt;mvsort&lt;/CODE&gt; which might help as well. Or have a look here, this guy created his own &lt;CODE&gt;mvdedup&lt;/CODE&gt; command with the sort feature: &lt;A href="http://answers.splunk.com/answers/11394/is-it-possible-to-sort-or-reorder-a-multivalue-field.html"&gt;http://answers.splunk.com/answers/11394/is-it-possible-to-sort-or-reorder-a-multivalue-field.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 23:20:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113321#M29807</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2014-11-05T23:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113322#M29808</link>
      <description>&lt;P&gt;Since I wanted to span multiple date fields, I came up with this code that seems to be working.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;convert mktime(*Date) as *DateEpoch timeformat="%a %b %d %H:%M:%S %Z %Y"
| eval CreateDateEpoch=now()+(60*60*24*365)
| foreach *DateEpoch
[eval CreateDateEpoch= if (typeof('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')=="Invalid", CreateDateEpoch, min(CreateDateEpoch, '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))]
| eval CreateDate = strftime(CreateDateEpoch, "%m/%d/%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Nov 2014 15:05:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113322#M29808</guid>
      <dc:creator>nfieglein</dc:creator>
      <dc:date>2014-11-06T15:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the earliest date in a multivalue field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113323#M29809</link>
      <description>&lt;P&gt;I am going to give both musskopf and myself a partial answer on this. His definitely find the right value in a single date multivalue and you could probably do the same thing with all of the date fields in an event. Mine is a bit more involved, but I only have one pass to get the earliest/latest date. You choose the one you like.&lt;/P&gt;

&lt;P&gt;My code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;convert mktime(*Date) as *DateEpoch timeformat="%a %b %d %H:%M:%S %Z %Y"
 | eval CreateDateEpoch=now()+(60*60*24*365)
 | foreach *DateEpoch
 [eval CreateDateEpoch= if (typeof('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')=="Invalid", CreateDateEpoch, min(CreateDateEpoch, '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))]
 | eval CreateDate = strftime(CreateDateEpoch, "%m/%d/%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Musskopf's code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=0 end=1 | eval mv="Fri Oct 31 00:00:00 CDT 2014,Mon Oct 27 00:00:00 CDT 2014,Sat Nov 01 00:00:00 CDT 2014,Thu Oct 30 00:00:00 CDT 2014,Tue Oct 28 00:00:00 CDT 2014,Wed Oct 29 00:00:00 CDT 2014" | makemv delim="," mv
 | eval datemv=strptime(mv,"%a %b %d %H:%M:%S CDT %Y")
 | eval most_recent_seconds=max(datemv)
 | eval most_recent_human=strftime(most_recent_seconds,"%a %b %d %H:%M:%S CDT %Y")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Nov 2014 21:30:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-earliest-date-in-a-multivalue-field/m-p/113323#M29809</guid>
      <dc:creator>nfieglein</dc:creator>
      <dc:date>2014-11-07T21:30:53Z</dc:date>
    </item>
  </channel>
</rss>

