<?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: Eval calculate time since event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632561#M219732</link>
    <description>&lt;P&gt;The strptime() function should be able to extract the timestamp from the field&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=issue ".+(?&amp;lt;timedate&amp;gt;\d{4}\s\d{2}\s[A-Z][a-z]{2})"
| eval Issue_Began=strptime(timedate." ".date_year,"%H%M %d %b %Y")&lt;/LI-CODE&gt;&lt;P&gt;and use fillnull&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fillnull value=0 D&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 28 Feb 2023 12:27:06 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-02-28T12:27:06Z</dc:date>
    <item>
      <title>How to eval calculate time since event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632559#M219731</link>
      <description>&lt;P&gt;I'm trying to add a "Downtime" field to my table. The timestamp on the event isn't reliable because it is when the issue was reported, not when it began so I had to extract the time from another field. This is a two-part question.&lt;/P&gt;
&lt;P&gt;1. Is there a better, more simple way to get my "Downtime" variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rex field=issue ".+(?P&amp;lt;S_Time&amp;gt;\d{4})[Z]\s(?P&amp;lt;S_Date&amp;gt;\d{2}\s[A-Z][a-z]{2})"&lt;BR /&gt;eval Issue_Began=S_Time. " ".S_Date." ".date_year&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;```Output ex - 0654 27 Feb 2023```&lt;BR /&gt;eval StartTime=strftime(strptime(Issue_Began, "%H%M %d %B %Y"), "%m/%d/%Y %H:%M")&lt;BR /&gt;eval duration=now()-strptime(StartTime, "%m/%d/%Y %H:%M")&lt;BR /&gt;eval duration=tostring(duration,"duration")&lt;BR /&gt;rex field=duration "((?P&amp;lt;D&amp;gt;\d{1,2})\+)?(?P&amp;lt;H&amp;gt;\d{2}):(?P&amp;lt;M&amp;gt;\d{2})" ```Output ex - 1+05:16.51```&lt;BR /&gt;eval Downtime=D."D ".H."H ".M."M "&lt;/P&gt;
&lt;P&gt;2. When a system is down for less than 24 hours, the Downtime field is blank, otherwise it will give me the expected result of "1D 05H 16M". How do I alter that eval to skip "D" if it is null? I'm assuming that's the issue because the field operates properly for all other events over 1 day long.&lt;/P&gt;
&lt;P&gt;Answers to either question is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 18:55:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632559#M219731</guid>
      <dc:creator>michaeler</dc:creator>
      <dc:date>2023-02-28T18:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632561#M219732</link>
      <description>&lt;P&gt;The strptime() function should be able to extract the timestamp from the field&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=issue ".+(?&amp;lt;timedate&amp;gt;\d{4}\s\d{2}\s[A-Z][a-z]{2})"
| eval Issue_Began=strptime(timedate." ".date_year,"%H%M %d %b %Y")&lt;/LI-CODE&gt;&lt;P&gt;and use fillnull&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fillnull value=0 D&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:27:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632561#M219732</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-28T12:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632562#M219733</link>
      <description>&lt;P&gt;1. Please, paste your code in preformatted block or code block - it greatly improves readability. Also, you forgot the pipes between different commands. In this case it's pretty understandable where they should be but it's not always the case.&lt;/P&gt;&lt;P&gt;2. Don't overthink! If you have a timestamp in the unix timestamp format (number of seconds since epoch), there's no more convenient form! With such a numerical field you can easily calculate offsets, differences and such. Only at the final step of your process you should render this to a datetime string or duration string.&lt;/P&gt;&lt;P&gt;So just strptime() your time fields, calculate the difference and you're good. Doing strptime and strftime several times in a row doesn't help you - it just introduces more points where you can do something wrong (for example by specifying wrong time format) and is more CPU-expensive.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632562#M219733</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-02-28T12:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632583#M219748</link>
      <description>&lt;P&gt;1. That would make it easier but the Splunk instance I manage has no internet connectivity so I have to manually retype it over.&lt;/P&gt;&lt;P&gt;2. Good point, I felt like I was over complicating it&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 13:47:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632583#M219748</guid>
      <dc:creator>michaeler</dc:creator>
      <dc:date>2023-02-28T13:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632587#M219751</link>
      <description>&lt;P&gt;In the issue field the time is displayed as&amp;nbsp;&lt;SPAN&gt;0654Z 27 Feb. Will this still work? Thats the only reason I extracted the time and day/month separately.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 13:54:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632587#M219751</guid>
      <dc:creator>michaeler</dc:creator>
      <dc:date>2023-02-28T13:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632592#M219753</link>
      <description>&lt;P&gt;Nevermind. Just added %Z in the eval and it worked fine. Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 14:10:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632592#M219753</guid>
      <dc:creator>michaeler</dc:creator>
      <dc:date>2023-02-28T14:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Eval calculate time since event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632594#M219754</link>
      <description>&lt;P&gt;Sorry, I forgot the Z, try this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=issue ".+(?&amp;lt;time&amp;gt;\d{4})Z\s(?&amp;lt;date&amp;gt;\d{2}\s[A-Z][a-z]{2})"
| eval Issue_Began=strptime(time." ".date." ".date_year,"%H%M %d %b %Y")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 14:14:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-eval-calculate-time-since-event/m-p/632594#M219754</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-28T14:14:45Z</dc:date>
    </item>
  </channel>
</rss>

