<?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 calculate the date difference for two timestamps other than _time and exclude weekends? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203249#M59049</link>
    <description>&lt;P&gt;@somesoni2  you're solution is fascinating.  I don't use the mvrange or mvcount much.  Can you explain what is happening in the eval &lt;CODE&gt;| eval dates=mvrange(strptime(Receivedate,"%m/%d/%Y"),strptime(Processdate,"%m/%d/%Y"),86400)&lt;/CODE&gt; please&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2016 13:18:27 GMT</pubDate>
    <dc:creator>hartfoml</dc:creator>
    <dc:date>2016-09-22T13:18:27Z</dc:date>
    <item>
      <title>How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203245#M59045</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
I have two timestamps , both are NOT &lt;CODE&gt;_time&lt;/CODE&gt;.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Received Date - 09/10/16&lt;/LI&gt;
&lt;LI&gt;Processed Date - 09/14/16&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I need to calculate the age of these two, but need to exclude weekends. I need something like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | eval age = (Processed Date - Received date). | table age
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the above example the result should be 2, so that weekend is excluded.. &lt;BR /&gt;
It should not be 4.&lt;/P&gt;

&lt;P&gt;I think &lt;CODE&gt;date_wday&lt;/CODE&gt; excludes days from &lt;CODE&gt;_time&lt;/CODE&gt; only. But for me the timestamp for calculating the age is not &lt;CODE&gt;_time&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Please advise on how to exclude the weekends. Also, please advise on how to exclude public holidays as well. Thanks so much in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 13:25:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203245#M59045</guid>
      <dc:creator>splunk_hvijay</dc:creator>
      <dc:date>2016-09-21T13:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203246#M59046</link>
      <description>&lt;P&gt;Try something like this (run anywhere sample, replace first line with your current search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Processdate="9/14/2016" | table Processdate| eval Receivedate="9/10/2016" 
| eval dates=mvrange(strptime(Receivedate,"%m/%d/%Y"),strptime(Processdate,"%m/%d/%Y"),86400) | convert ctime(dates)  timeformat="%A" | eval dates=mvfilter(NOT match(dates,"(Saturday|Sunday)")) | eval noOfDays=mvcount(dates)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2016 15:42:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203246#M59046</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-21T15:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203247#M59047</link>
      <description>&lt;P&gt;Thanks so much. excellent.. this worked for me.. BTW, i didnt use  gentimes start=-1, is it mandatory?&lt;/P&gt;

&lt;P&gt;And how to exclude public holidays...thanks again for your help&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 02:43:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203247#M59047</guid>
      <dc:creator>splunk_hvijay</dc:creator>
      <dc:date>2016-09-22T02:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203248#M59048</link>
      <description>&lt;P&gt;This line is to generate a sample data to show the remaining processing steps. The whole thing should be replaced by your search which get the required data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Processdate="9/14/2016" | table Processdate| eval Receivedate="9/10/2016"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is no in-build way to identify public holidays in Splunk, you would need to create some custom lookup with dates which are publich holidays and exclude them (not straightforward way. Don't have a ready to use solution, will need to figure that one out).&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 04:10:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203248#M59048</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-22T04:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203249#M59049</link>
      <description>&lt;P&gt;@somesoni2  you're solution is fascinating.  I don't use the mvrange or mvcount much.  Can you explain what is happening in the eval &lt;CODE&gt;| eval dates=mvrange(strptime(Receivedate,"%m/%d/%Y"),strptime(Processdate,"%m/%d/%Y"),86400)&lt;/CODE&gt; please&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 13:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203249#M59049</guid>
      <dc:creator>hartfoml</dc:creator>
      <dc:date>2016-09-22T13:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203250#M59050</link>
      <description>&lt;P&gt;It's basically creating a multivalued field dates with arithmetic series starting with epoch value of Receivedate, ending at epoch value of Processdata, with step of 86400 (1 day in secs). I think it would be clearer if you can run this query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | gentimes start=-1 | eval Processdate="9/14/2016" | table Processdate| eval Receivedate="9/10/2016" | eval dates_epoch=mvrange(strptime(Receivedate,"%m/%d/%Y"),strptime(Processdate,"%m/%d/%Y"),86400) 
| convert ctime(dates_epoch) as dates_human
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Sep 2016 14:50:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203250#M59050</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-22T14:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203251#M59051</link>
      <description>&lt;P&gt;@somesoni2 : Do you have the solution to identify holidays yet ?&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 09:10:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203251#M59051</guid>
      <dc:creator>RRajneesh</dc:creator>
      <dc:date>2018-05-03T09:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203252#M59052</link>
      <description>&lt;P&gt;I think so. As I mentioned before, for excluding public holidays, you'd need to setup a lookup table with list of holidays. You can find one here: &lt;A href="https://gist.github.com/shivaas/4758439"&gt;https://gist.github.com/shivaas/4758439&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Once you've your lookup table setup, say holidays.csv with column date (holiday date in format &lt;CODE&gt;%Y-%m-%d&lt;/CODE&gt;,name (don't really care for this column), your query would be like this (using a sample data):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval Processdate="06/01/2018" | table Processdate| eval Receivedate="05/01/2018"  
   | eval dates=mvrange(strptime(Receivedate,"%m/%d/%Y"),strptime(Processdate,"%m/%d/%Y"),86400) | convert ctime(dates) timeformat="%A %Y-%m-%d" | eval workdays=mvfilter(NOT match(dates,[| inputlookup holidays.csv | stats values(date) as date| eval date=mvappend("(Saturday",date,"Sunday)")| eval search=mvjoin(date,"|") | table search | format "" "" "" "" "" ""])) | eval noOfDays=mvcount(dates)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 May 2018 16:12:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203252#M59052</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-03T16:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I calculate the date difference for two timestamps other than _time and exclude weekends?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203253#M59053</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for your reply.&lt;/P&gt;

&lt;P&gt;Getting the below error :&lt;/P&gt;

&lt;P&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ') ))'.&lt;/P&gt;

&lt;P&gt;Also, the last part, shouldn't it be mvcount(workdays) instead of mvcount(dates) ?&lt;/P&gt;

&lt;P&gt;Thanks in advance for your reply.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 16:37:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-calculate-the-date-difference-for-two-timestamps-other/m-p/203253#M59053</guid>
      <dc:creator>RRajneesh</dc:creator>
      <dc:date>2018-05-03T16:37:19Z</dc:date>
    </item>
  </channel>
</rss>

