<?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 get the difference between 2 date fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595298#M207173</link>
    <description>&lt;P&gt;thank you&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Apr 2022 21:27:09 GMT</pubDate>
    <dc:creator>ajdyer2000</dc:creator>
    <dc:date>2022-04-25T21:27:09Z</dc:date>
    <item>
      <title>How to get the difference between 2 date fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595289#M207165</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;
&lt;P&gt;thank you all so much for helping me. this is a great forum to learn.&lt;/P&gt;
&lt;P&gt;I have 2 date fields and I'd like to get the difference in days and if they are over certain thresholds &amp;lt;30 ,&amp;gt;30, &amp;gt;60, &amp;gt;120&lt;/P&gt;
&lt;P&gt;For Example&lt;/P&gt;
&lt;TABLE width="345"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="86"&gt;Current-Date&lt;/TD&gt;
&lt;TD width="77"&gt;Open-Date&lt;/TD&gt;
&lt;TD width="109"&gt;Diff Days&amp;nbsp;&lt;/TD&gt;
&lt;TD width="73"&gt;Metric&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;4/23/2022&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&amp;lt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;3/15/2022&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;41&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;30&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;2/15/2022&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;69&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;60&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;12/25/2021&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;121&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;120&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;4/1/2022&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;11/25/2021&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4/25/2022&lt;/TD&gt;
&lt;TD&gt;1/15/2022&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;??&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 19:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595289#M207165</guid>
      <dc:creator>ajdyer2000</dc:creator>
      <dc:date>2022-04-25T19:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the difference between 2 date fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595290#M207166</link>
      <description>&lt;P&gt;To compare dates they must first be in epoch (integer) format.&amp;nbsp; Use the strptime function to do that.&amp;nbsp; Then you can subtract to the difference.&amp;nbsp; The result will be in seconds so divide by 86400 to get days.&amp;nbsp; The Metric field is just a case statement.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval current_epoch=strptime('Current-Date', "%m/%d/%Y"), open_epoch=strptime('Open-Date', "%m/%d/%Y")
| eval diff=(current_epoch - open_epoch) / 86400
| eval Metric=case(diff&amp;lt;30,"&amp;lt;30", diff&amp;gt;120,"&amp;gt;120", diff&amp;gt;60,"&amp;gt;60", diff&amp;gt;30,"&amp;gt;30")
| rename diff as "Diff Days"&lt;/LI-CODE&gt;&lt;P&gt;BTW, try to avoid hyphens in field names as they just complicate the SPL.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 19:34:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595290#M207166</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-04-25T19:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the difference between 2 date fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595291#M207167</link>
      <description>&lt;P&gt;Main question here is what is the form of your dates. If they are unix timestamps, just substract one from another and you're home. If they're strings (as in your example), you have to first parse them to timestamps.&lt;/P&gt;&lt;PRE&gt;&amp;lt;your search&amp;gt;&lt;BR /&gt;| eval opentimestamp=strptime('Open-Date',"%m/%d/%Y")&lt;BR /&gt;| eval currenttimestamp=strptimr('Current-Date',"%m/%d/%Y")&lt;BR /&gt;| eval diffdays=(currenttimestamp-opentimestamp)/86400&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2022 19:37:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595291#M207167</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-04-25T19:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the difference between 2 date fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595298#M207173</link>
      <description>&lt;P&gt;thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 21:27:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-difference-between-2-date-fields/m-p/595298#M207173</guid>
      <dc:creator>ajdyer2000</dc:creator>
      <dc:date>2022-04-25T21:27:09Z</dc:date>
    </item>
  </channel>
</rss>

