<?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: about date and time form in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23702#M177477</link>
    <description>&lt;P&gt;The sample you provided has another date format than what you posted in earlier events, so if that's the format you're working with you should change the strptime format string to reflect that.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Aug 2012 07:10:16 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-08-03T07:10:16Z</dc:date>
    <item>
      <title>about date and time form</title>
      <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23699#M177474</link>
      <description>&lt;P&gt;There are "date-time" fields other than _time in events:&lt;BR /&gt;
...^2012/06/30 23:58:20^2012/06/30 23:58:20...&lt;BR /&gt;
we pre extracted them as "firsttime","lasttime"&lt;BR /&gt;
we want the results where (fisttime-lasttime)&amp;lt;300s, how could we approach that?&lt;BR /&gt;
I have tried search as:&lt;BR /&gt;
| rex field=firsttime "(?&lt;FDATE&gt;\d{2}/\d{2}/\d{2})\s(?&lt;FTIME&gt;\d{2}:\d{2}:\d{2})" &lt;BR /&gt;
| rex field=lasttime "(?&lt;LDATE&gt;\d{2}/\d{2}/\d{2})\s(?&lt;LTIME&gt;\d{2}:\d{2}:\d{2})"&lt;BR /&gt;
| convert dur2sec(ftime), dur2sec(ltime)&lt;BR /&gt;
| where fdate=ldate | eval duration=ltime-ftime |where duration&amp;lt;300 | &lt;BR /&gt;
but this is not impeccable.&lt;/LTIME&gt;&lt;/LDATE&gt;&lt;/FTIME&gt;&lt;/FDATE&gt;&lt;/P&gt;

&lt;P&gt;Edit:&lt;BR /&gt;
Hi&lt;BR /&gt;
This solution so cool&lt;BR /&gt;
But it seems not willing to work, I dont know what I did wrong: &lt;/P&gt;

&lt;P&gt;sourcetype="..." | fields FirstOccurrence LastOccurrence &lt;BR /&gt;
| eval firsttime_epoch=strptime(FirstOccurrence,"%Y/%m/%d %H:%M:%S")&lt;BR /&gt;
| eval lasttime_epoch=strptime(LastOccurrence,"%Y/%m/%d %H:%M:%S")&lt;BR /&gt;
| table FirstOccurrence firsttime_epoch There are values in FirstOccurrence  but firsttime_epoch not&lt;BR /&gt;
one of samples:&lt;BR /&gt;
1/10/11 12:08:58&lt;/P&gt;

&lt;P&gt;(just now)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:11:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23699#M177474</guid>
      <dc:creator>crazyeva</dc:creator>
      <dc:date>2020-09-28T12:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: about date and time form</title>
      <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23700#M177475</link>
      <description>&lt;P&gt;A better way would probably be to use &lt;CODE&gt;eval&lt;/CODE&gt;'s &lt;CODE&gt;strptime&lt;/CODE&gt; function to convert the timestamp strings to epoch values and then use these in your comparison.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval firsttime_epoch=strptime(firsttime,"%Y/%m/%d %H:%M:%S")
| eval lasttime_epoch=strptime(lasttime,"%Y/%m/%d %H:%M:%S")
| where lasttime_epoch-firsttime_epoch&amp;lt;300
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2012 09:21:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23700#M177475</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-08-02T09:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: about date and time form</title>
      <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23701#M177476</link>
      <description>&lt;P&gt;Thank you very much !&lt;BR /&gt;
That is professional&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2012 09:29:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23701#M177476</guid>
      <dc:creator>crazyeva</dc:creator>
      <dc:date>2012-08-02T09:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: about date and time form</title>
      <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23702#M177477</link>
      <description>&lt;P&gt;The sample you provided has another date format than what you posted in earlier events, so if that's the format you're working with you should change the strptime format string to reflect that.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2012 07:10:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23702#M177477</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-08-03T07:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: about date and time form</title>
      <link>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23703#M177478</link>
      <description>&lt;P&gt;Thank you again&lt;BR /&gt;
| eval firsttime_epoch=strptime(FirstOccurrence,"%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval lasttime_epoch=strptime(LastOccurrence,"%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval firsttime_epoch2=strptime(FirstOccurrence,"%m/%d/%y %H:%M:%S")&lt;BR /&gt;
| eval lasttime_epoch2=strptime(LastOccurrence,"%m/%d/%y %H:%M:%S")&lt;BR /&gt;
| where lasttime_epoch-firsttime_epoch&amp;lt;300 OR lasttime_epoch2-firsttime_epoch2&amp;lt;300&lt;BR /&gt;
then it works&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:11:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/about-date-and-time-form/m-p/23703#M177478</guid>
      <dc:creator>crazyeva</dc:creator>
      <dc:date>2020-09-28T12:11:42Z</dc:date>
    </item>
  </channel>
</rss>

