<?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 difference of time between the 2 fields ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674299#M230814</link>
    <description>&lt;P&gt;Datetime calculations such as finding the difference should be done with epoch times so rather than formatting now() you should be parsing timestampOfReception using strptime() so you can subtract one from the other.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2024 17:32:17 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2024-01-15T17:32:17Z</dc:date>
    <item>
      <title>How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674287#M230811</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please tell me how can i&amp;nbsp; extract the&amp;nbsp;events for which the difference of &lt;STRONG&gt;current_time&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;timestampOfReception&lt;/STRONG&gt; is greater that 4 hours for the below Splunk query :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;`eoc_stp_events_indexes` host=p* OR host=azure_srt_prd_0001 (messageType= seev.047* OR messageType= SEEV.047*) status = SUCCESS targetPlatform = SRS_ESES
NOT [ search (index=events_prod_srt_shareholders_esa OR index=eoc_srt) seev.047 Name="Received Disclosure Response Command"
| spath input=Properties.appHdr
| rename bizMsgIdr as messageBusinessIdentifier
| fields messageBusinessIdentifier ]
| eval Current_time =strftime(now(),"%Y-%m-%d %H:%M:%S ")
| eval diff= Current_time-timestampOfReception
| fillnull timestampOfReception , messageOriginIdentifier, messageBusinessIdentifier, direction, messageType, currentPlatform, sAAUserReference value="-"
| sort -timestampOfReception
| table diff , Current_time, timestampOfReception, messageOriginIdentifier, messageType, status, messageBusinessIdentifier, originPlatform, direction, sourcePlatform, currentPlatform, targetPlatform, senderIdentifier, receiverIdentifier, currentPlatform,
| rename timestampOfReception AS "Timestamp of reception", originPlatform AS "Origin platform", sourcePlatform AS "Source platform", targetPlatform AS "Target platform", senderIdentifier AS "Sender identifier", receiverIdentifier AS "Receiver identifier",
messageOriginIdentifier AS "Origin identifier", messageBusinessIdentifier AS "Business identifier", direction AS Direction, currentPlatform AS "Current platform", sAAUserReference AS "SAA user reference", messageType AS "Message type"&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 15 Jan 2024 16:54:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674287#M230811</guid>
      <dc:creator>Real_captain</dc:creator>
      <dc:date>2024-01-15T16:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674299#M230814</link>
      <description>&lt;P&gt;Datetime calculations such as finding the difference should be done with epoch times so rather than formatting now() you should be parsing timestampOfReception using strptime() so you can subtract one from the other.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 17:32:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674299#M230814</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-01-15T17:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674320#M230821</link>
      <description>&lt;P&gt;Also if timestampOfReception is the main timestamp of the event, it should be properly parsed as _time field of the event. It makes searching the events much, much quicker.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 22:05:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674320#M230821</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-01-15T22:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674350#M230835</link>
      <description>&lt;P&gt;i am not able to find the difference of time using the below clause :&lt;/P&gt;&lt;P&gt;Can you please tell me what i should add to get the difference of the 2 timestamps.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;| eval diff= Current_time-timestampOfReception&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Complete search :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;`eoc_stp_events_indexes` host=p* OR host=azure_srt_prd_0001 (messageType= seev.047* OR messageType= SEEV.047*) status = SUCCESS targetPlatform = SRS_ESES
NOT [ search (index=events_prod_srt_shareholders_esa OR index=eoc_srt) seev.047 Name="Received Disclosure Response Command"
| spath input=Properties.appHdr
| rename bizMsgIdr as messageBusinessIdentifier
| fields messageBusinessIdentifier ]
| eval Current_time =strftime(now(),"%Y-%m-%d %H:%M:%S ")
| eval diff= Current_time-timestampOfReception
| fillnull timestampOfReception , messageOriginIdentifier, messageBusinessIdentifier, direction, messageType, currentPlatform, sAAUserReference value="-"
| sort -timestampOfReception
| table diff , Current_time, timestampOfReception, messageOriginIdentifier, messageType, status, messageBusinessIdentifier, originPlatform, direction, sourcePlatform, currentPlatform, targetPlatform, senderIdentifier, receiverIdentifier, currentPlatform,
| rename timestampOfReception AS "Timestamp of reception", originPlatform AS "Origin platform", sourcePlatform AS "Source platform", targetPlatform AS "Target platform", senderIdentifier AS "Sender identifier", receiverIdentifier AS "Receiver identifier",
messageOriginIdentifier AS "Origin identifier", messageBusinessIdentifier AS "Business identifier", direction AS Direction, currentPlatform AS "Current platform", sAAUserReference AS "SAA user reference", messageType AS "Message type"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Real_captain_0-1705400299019.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28948iB02194A01E1C28AE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Real_captain_0-1705400299019.png" alt="Real_captain_0-1705400299019.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 10:18:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674350#M230835</guid>
      <dc:creator>Real_captain</dc:creator>
      <dc:date>2024-01-16T10:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674353#M230837</link>
      <description>&lt;P&gt;Apart from all the things we already said with &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt; your main problem here is this:&lt;/P&gt;&lt;PRE&gt;| eval Current_time =strftime(now(),"%Y-%m-%d %H:%M:%S ")
| eval diff= Current_time-timestampOfReception&lt;/PRE&gt;&lt;P&gt;with the fact that most probably your timestampOfReception is also a string field from your event (you're not strptime()-ing it anywhere in your search so I can safely assume that).&lt;/P&gt;&lt;P&gt;What you're trying to do is running a substraction operation on two strings. It won't fly. Strings are not substractable (also they are not additive in Splunk, you need to use concatenation operator).&lt;/P&gt;&lt;P&gt;So you won't get any value at all and that's normal in this case.&lt;/P&gt;&lt;P&gt;What you need to do is to use strptime() (not strftime()!) to parse the timestampOfReception field to the so-called unix-timestamp (which is the number of seconds from epoch which means it's a number) and substract it from the value of now() which is also returned as unix-timestamp. There is no need to formatting any of that into strings. Quite contrary - you want both of those timestamps as numbers because then you can easily manipulate them.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 10:26:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674353#M230837</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-01-16T10:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674363#M230840</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even with&amp;nbsp;strptime , i am not able to find the difference of current time and&amp;nbsp;timestampOfReception. i am using the below criteria.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me to extract the difference of current time and&amp;nbsp;timestampOfReception in the&amp;nbsp;diff field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And&amp;nbsp;strptime is not working with the the function now ().&amp;nbsp;&lt;/P&gt;&lt;P&gt;`eoc_stp_events_indexes` host=p* OR host=azure_srt_prd_0001 (messageType= seev.047* OR messageType= SEEV.047*) status = SUCCESS targetPlatform = SRS_ESES&lt;BR /&gt;NOT [ search (index=events_prod_srt_shareholders_esa OR index=eoc_srt) seev.047 Name="Received Disclosure Response Command"&lt;BR /&gt;| spath input=Properties.appHdr&lt;BR /&gt;| rename bizMsgIdr as messageBusinessIdentifier&lt;BR /&gt;| fields messageBusinessIdentifier ]&lt;BR /&gt;&lt;STRONG&gt;| eval Current_time =strftime(now(),"%Y-%m-%d %H:%M:%S ")&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval reception_time =strptime( timestampOfReception , "%Y-%m-%d%H:%M:%S.%N" ) &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval diff= current_time - reception_time&lt;/STRONG&gt;&lt;BR /&gt;| fillnull timestampOfReception , messageOriginIdentifier, messageBusinessIdentifier, direction, messageType, currentPlatform, sAAUserReference value="-"&lt;BR /&gt;| sort -timestampOfReception&lt;BR /&gt;| table diff , reception_time, Current_time , timestampOfReception, messageOriginIdentifier, messageType, status, messageBusinessIdentifier, originPlatform, direction, sourcePlatform, currentPlatform, targetPlatform, senderIdentifier, receiverIdentifier, currentPlatform,&lt;BR /&gt;| rename timestampOfReception AS "Timestamp of reception", originPlatform AS "Origin platform", sourcePlatform AS "Source platform", targetPlatform AS "Target platform", senderIdentifier AS "Sender identifier", receiverIdentifier AS "Receiver identifier",&lt;BR /&gt;messageOriginIdentifier AS "Origin identifier", messageBusinessIdentifier AS "Business identifier", direction AS Direction, currentPlatform AS "Current platform", sAAUserReference AS "SAA user reference", messageType AS "Message type"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Real_captain_0-1705410311477.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28949iC137F91DF6B903AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Real_captain_0-1705410311477.png" alt="Real_captain_0-1705410311477.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 13:05:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674363#M230840</guid>
      <dc:creator>Real_captain</dc:creator>
      <dc:date>2024-01-16T13:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674364#M230841</link>
      <description>&lt;LI-CODE lang="markup"&gt;| eval diff= now() - reception_time&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 16 Jan 2024 13:22:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674364#M230841</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-01-16T13:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the difference of time between the 2 fields ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674365#M230842</link>
      <description>&lt;P&gt;As &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt; already showed - there's no point of strftime'ing now() just to do strptime() on the result back to get the unix timestamp. Just use the value of now() directly.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 13:36:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-difference-of-time-between-the-2-fields/m-p/674365#M230842</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-01-16T13:36:19Z</dc:date>
    </item>
  </channel>
</rss>

