<?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 do I find the time difference for each change in the location of the city? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618678#M215028</link>
    <description>&lt;P&gt;After the previous stats, count in this context is just the result from that stats function named count. &amp;nbsp;This is a roundabout way to say in&amp;nbsp;&lt;SPAN&gt;mvrange(1, &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;&lt;SPAN&gt;), &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;&amp;nbsp;is merely a field name.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 04:24:25 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-10-28T04:24:25Z</dc:date>
    <item>
      <title>How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618325#M214895</link>
      <description>&lt;P&gt;I have a query like this:&lt;/P&gt;&lt;H6&gt;| dbxquery connection=xxxxx&amp;nbsp; query="select xxx FROM xxx WHERE xxx and to_char(LOG_DATE_TIME,'YYYY-MM-DD')='2022-10-13'"&lt;BR /&gt;| iplocation SRC_IP&lt;BR /&gt;| stats values(LOG_DATE_TIME) as TIME dc(City) as countCity list(City) as city values(SRC_IP) as sourceIp by CIF USER_CD&lt;BR /&gt;| eval time = strptime(TIME,"%Y-%m-%d %H:%M:%S.%3N")&lt;BR /&gt;| eval differenceMinutes=(max(time)-min(time))/60&lt;BR /&gt;| fields - time&lt;BR /&gt;| search countCity&amp;gt;1 AND differenceHours&amp;gt;1&lt;/H6&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The query displays the result like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="time2200_0-1666766907354.png" style="width: 730px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22139i917FC52C89A36BA2/image-dimensions/730x99?v=v2" width="730" height="99" role="button" title="time2200_0-1666766907354.png" alt="time2200_0-1666766907354.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want it to have a result like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="time2200_0-1666768794202.png" style="width: 800px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22141i9F5D8189FA0F718C/image-dimensions/800x119?v=v2" width="800" height="119" role="button" title="time2200_0-1666768794202.png" alt="time2200_0-1666768794202.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="time2200_3-1666769836158.png" style="width: 800px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22144i16F2F258EF0BEC9F/image-dimensions/800x112?v=v2" width="800" height="112" role="button" title="time2200_3-1666769836158.png" alt="time2200_3-1666769836158.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;BR /&gt;Jakarta - Bogor&lt;/P&gt;&lt;P&gt;(LOG_DATE_TIME&amp;nbsp; - string type data)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2022-10-13 09:03:33.539&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; 2022-10-13 09:00:55.885&lt;/P&gt;&lt;P&gt;(already converted in timestamps version)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1665626613.539000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1665626455.885000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; 158 (in seconds)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then 158/60 = 2.633 minutes&lt;/P&gt;&lt;P&gt;Bogor - Jakarta =&amp;nbsp; 9.22 minutes&lt;/P&gt;&lt;P&gt;Jakarta - Bogor = 360 minutes&lt;/P&gt;&lt;P&gt;Bogor - Jakarta = 240 minutes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should my query be, in order to achieve that result?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 07:42:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618325#M214895</guid>
      <dc:creator>time2200</dc:creator>
      <dc:date>2022-10-26T07:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618343#M214907</link>
      <description>&lt;P&gt;The requirements is very unclear because there is no explanation of the data. &amp;nbsp;If I have to speculate, fields&amp;nbsp;&amp;nbsp;CIF and USER_CD uniquely identifies a certain user activity (let's call it a transaction); each event has a SRC_IP field, and a LOG_DATE_TIME field that is a timestamp in&amp;nbsp;&lt;SPAN&gt;"%Y-%m-%d %H:%M:%S.%3N" format. &amp;nbsp;You want to reveal some characteristics of this transaction using geolocation and lapsed time &lt;EM&gt;between&lt;/EM&gt; mapped geolocation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If this is your requirement, the mockup display is perhaps not the best format. &amp;nbsp;But set that aside, the stats you illustrated will only give you the total lapsed time during this "transaction", not the lapse between cities you wanted. &amp;nbsp; To do that, you must calculate the characteristics between each event pair.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery connection=xxxxx  query="select xxx FROM xxx WHERE xxx and to_char(LOG_DATE_TIME,'YYYY-MM-DD')='2022-10-13'"
| iplocation SRC_IP
| stats count values(LOG_DATE_TIME) as TIME dc(City) as countCity list(City) as city values(SRC_IP) as sourceIp by CIF USER_CD
| eval time = strptime(TIME,"%Y-%m-%d %H:%M:%S.%3N")
| eval differenceHours = (max(time) - min(time)) / 3600
| search countCity&amp;gt;1 AND differenceHours&amp;gt;1
| eval iter = mvrange(1, count)
| eval differenceMinutes = mvmap(iter, (mvindex(time, iter) - mvindex(time, iter - 1))/60)
| fields - time&lt;/LI-CODE&gt;&lt;P&gt;Note you didn't specify the definition of differenceHours, so I have to invent one, and that leads me to move the search command up. &amp;nbsp;Most importantly, the above is not exactly what you expect, to calculate lapsed time only when city changes. &amp;nbsp;I can think of a relatively simple way to achieve that if each city only encompass a maximum of two events. &amp;nbsp;But if there can be more, aggregation will need more refinements. &amp;nbsp;The above should point you to the right direction, however.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 09:32:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618343#M214907</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-10-26T09:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618357#M214910</link>
      <description>&lt;P&gt;CIF and USER_CD uniquely identifies a certain user activity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v&amp;nbsp; TRUE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;value of LOG_DATE_TIME correlated with City&lt;BR /&gt;are successive real-time events.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the differenceHours field will be deprecated because it only takes the earliest and last times.&lt;/P&gt;&lt;P&gt;my goal is to calculate the time difference obtained by differentiating each location change, with units of minutes, which will be entered into the differenceMinutes field.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="resultsMinutes.png" style="width: 761px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22147i8DD01941CD1D98A6/image-dimensions/761x234?v=v2" width="761" height="234" role="button" title="resultsMinutes.png" alt="resultsMinutes.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 10:59:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618357#M214910</guid>
      <dc:creator>time2200</dc:creator>
      <dc:date>2022-10-26T10:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618525#M214984</link>
      <description>&lt;P&gt;One more ambiguity: differenceMinutes can be defined as the time lapse between the first event in two consecutive geolocations, or it can be the time lapse between the last event in the last geolocation and the first event of the subsequent geolocation. &amp;nbsp;I will take the latter assumption, the calculation of which is considerably more complex. (If the former, some form of &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Dedup" target="_blank" rel="noopener"&gt;dedup&lt;/A&gt; will suffice.)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| dbxquery connection=xxxxx  query="select xxx FROM xxx WHERE xxx and to_char(LOG_DATE_TIME,'YYYY-MM-DD')='2022-10-13'"
| iplocation SRC_IP
| stats count values(LOG_DATE_TIME) as TIME dc(City) as countCity list(City) as city values(SRC_IP) as sourceIp by CIF USER_CD ``` calculate sequence ```
| eval time = strptime(TIME,"%Y-%m-%d %H:%M:%S.%3N")
| eval differenceHours = (max(time) - min(time)) / 3600
| search countCity&amp;gt;1 AND differenceHours&amp;gt;1
| eval iter = mvrange(1, count) ``` iter is the iterator of each event ```
| eval seq = 1 ``` seq is the sequence number of each new location ```
| eval seq = mvmap(iter, if(mvindex(city, iter) == mvindex(city, iter - 1), seq, seq + 1))
| stats min(time) as time max(time) as time_exit values(sourceIp) as sourceIp by CIF USER_CD seq city ``` extract entrance and exit times ```
| eval sourceIp = mvjoin(sourceIp, ", ") ``` to help with display ```
| stats values(time) as time list(time_exit) as time_exit list(seq) as seq list(city) as city list(sourceIp) as sourceIp by CIF USER_CD
``` use seq as the new iterator ```
| eval differenceMinutes = mvmap(seq, (mvindex(time, seq) - mvindex(time, seq - 1) + mvindex(time_exit, seq - 1))/60)
``` difference is caculated between exit time and next entrance time ```
| fields - time* iter seq&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Hope the comments will give you some idea.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 05:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618525#M214984</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-10-27T05:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618676#M215027</link>
      <description>&lt;P&gt;| eval iter = mvrange(1, &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;) ``` iter is the iterator of each event ```&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;bro, what is the &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt; function inside mvrange(1, count)?&lt;/P&gt;&lt;P&gt;i need to understand this query&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 04:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618676#M215027</guid>
      <dc:creator>time2200</dc:creator>
      <dc:date>2022-10-28T04:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the time difference for each change in the location of the city?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618678#M215028</link>
      <description>&lt;P&gt;After the previous stats, count in this context is just the result from that stats function named count. &amp;nbsp;This is a roundabout way to say in&amp;nbsp;&lt;SPAN&gt;mvrange(1, &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;&lt;SPAN&gt;), &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt;&amp;nbsp;is merely a field name.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 04:24:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-find-the-time-difference-for-each-change-in-the/m-p/618678#M215028</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-10-28T04:24:25Z</dc:date>
    </item>
  </channel>
</rss>

