<?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 How to compare dates for expiration purposes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295716#M89226</link>
    <description>&lt;P&gt;Greetings,&lt;BR /&gt;
I am trying to create a panel that helps me track expired trainings. What I am trying to do is to take the Class_Date and add 1year to it then compare that to todays date. So, IF Class_Date + 1 year &amp;gt; todays date, "Expired", "Valid".&lt;/P&gt;

&lt;P&gt;This is what I have so far:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup Classes.csv
| eval timenow = strftime(now(), "%Y-%m-%d")
| eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")
| eval ConvertedClassDate = ConvertedClassDate + 31536000)
| eval ConvertedTodaysDate = strptime(timenow, "%Y-%m-%d")
| eval Status = IF((ConvertedTodays_Date &amp;lt; ConvertedClassDate), "Expired", "Valid")
| table Username, Class_Date, Status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All help is greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 18:07:44 GMT</pubDate>
    <dc:creator>albinortiz</dc:creator>
    <dc:date>2020-09-29T18:07:44Z</dc:date>
    <item>
      <title>How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295716#M89226</link>
      <description>&lt;P&gt;Greetings,&lt;BR /&gt;
I am trying to create a panel that helps me track expired trainings. What I am trying to do is to take the Class_Date and add 1year to it then compare that to todays date. So, IF Class_Date + 1 year &amp;gt; todays date, "Expired", "Valid".&lt;/P&gt;

&lt;P&gt;This is what I have so far:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup Classes.csv
| eval timenow = strftime(now(), "%Y-%m-%d")
| eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")
| eval ConvertedClassDate = ConvertedClassDate + 31536000)
| eval ConvertedTodaysDate = strptime(timenow, "%Y-%m-%d")
| eval Status = IF((ConvertedTodays_Date &amp;lt; ConvertedClassDate), "Expired", "Valid")
| table Username, Class_Date, Status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All help is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:07:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295716#M89226</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2020-09-29T18:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295717#M89227</link>
      <description>&lt;P&gt;now() is already in epoch so no need to convert...simply you can compare like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so you can try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup Classes.csv
| eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")
| eval ConvertedClassDate = ConvertedClassDate + 31536000)
| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")
| table Username, Class_Date, Status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here Class_Date is expected in Year-month-day format like 2018-02-15&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 16:36:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295717#M89227</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-15T16:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295718#M89228</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am almost there. I can see the valid and expired ones. However, this is happening:&lt;/P&gt;

&lt;P&gt;username1   2018-1-1 Valid&lt;BR /&gt;
username3   2018-12-12 Valid&lt;BR /&gt;
username4   2017-1-2 Expired&lt;BR /&gt;
username5   2017-1-3 Expired&lt;/P&gt;

&lt;P&gt;The first entry should be expired since today's date is 2018-02-15. Why is the code making the comparison using the year?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 06:09:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295718#M89228</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2018-02-16T06:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295719#M89229</link>
      <description>&lt;P&gt;When I tried I get exact reverse output ...check what sign you are using &lt;CODE&gt;&amp;gt;&lt;/CODE&gt; or &lt;CODE&gt;&amp;lt;&lt;/CODE&gt;  in eval expression:&lt;BR /&gt;
Try this run anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval Class_Date="2018-1-1"
|append[|makeresults|eval Class_Date="2018-12-12"]
|append[|makeresults|eval Class_Date="2017-1-2"]
|append[|makeresults|eval Class_Date="2017-1-3"]
| eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")
 | eval ConvertedClassDate = ConvertedClassDate + 31536000 |eval current=now()| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Feb 2018 06:27:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295719#M89229</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-16T06:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295720#M89230</link>
      <description>&lt;P&gt;The issue I see is that 2018-12-12 is not expired and it is marking it as expired. If I change the comparison character, it will say 2018-01-01 is valid when in reality it is not. I feel like it is making the comparison using the year and not the whole date. &lt;/P&gt;

&lt;P&gt;Username    ClassDate   Status&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;username1    2018-1-1            Valid&lt;BR /&gt;
username2    2018-1-1            Valid&lt;/P&gt;

&lt;P&gt;These two lines should be Expired.&lt;/P&gt;

&lt;P&gt;I tried yours and it also does the same thing. &lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 21:31:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295720#M89230</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2018-02-16T21:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295721#M89231</link>
      <description>&lt;P&gt;If I tried for date 2018-1-1 it is coming as expired only as expected ...Not sure why are receiving it as valid...could you please provide your query and also try below query :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval Class_Date="2018-1-1"
| eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")
  | eval ConvertedClassDate = ConvertedClassDate + 31536000 |eval current=now()| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 00:51:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295721#M89231</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-17T00:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295722#M89232</link>
      <description>&lt;P&gt;Here's my code:&lt;BR /&gt;
| inputlookup Training.csv&lt;BR /&gt;
| eval ConvertedClassDate = strptime(ClassDate, "%Y-%m-%d")&lt;BR /&gt;
| eval ConvertedClassDate = (ConvertedClassDate + 31536000)&lt;BR /&gt;
| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")&lt;BR /&gt;
| table Username, ClassDate, Status&lt;/P&gt;

&lt;P&gt;I changed the date your code so you would see what is going on:&lt;/P&gt;

&lt;P&gt;|makeresults|eval Class_Date="2018-12-12"&lt;BR /&gt;
 | eval ConvertedClassDate = strptime(Class_Date, "%Y-%m-%d")&lt;BR /&gt;
   | eval ConvertedClassDate = ConvertedClassDate + 31536000 |eval current=now()| eval Status = IF((now() &amp;lt; ConvertedClassDate), "Expired", "Valid")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:04:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295722#M89232</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2020-09-29T18:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295723#M89233</link>
      <description>&lt;P&gt;You may consider using &lt;CODE&gt;relative_time&lt;/CODE&gt; instead of adding a year's worth of seconds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval ConvertedClassDate = relative_time(ConvertedClassDate, "+1y")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:01:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295723#M89233</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-17T01:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295724#M89234</link>
      <description>&lt;P&gt;I'm not sure where the above effort stood, but this seems to work, and is based from the same makeresults set:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Class_Date="2018-1-1" 
| append [| makeresults | eval Class_Date="2018-12-12"] 
| append [| makeresults | eval Class_Date="2017-1-2"] 
| append [| makeresults | eval Class_Date="2017-1-3"] 
| eval class_plus_one_year = relative_time(strptime(Class_Date, "%Y-%m-%d"), "+1y")
| eval Status = if(now() &amp;gt; class_plus_one_year, "Expired", "Valid")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:06:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295724#M89234</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-17T01:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295725#M89235</link>
      <description>&lt;P&gt;here logic is that :&lt;BR /&gt;
if (Classdate + 1year ) is less than today's date then it is expired else Valid...&lt;BR /&gt;
if it is correct logic then &lt;BR /&gt;
for classdate=2018-12-12 +1year=2019-12-12 is not less than todays date so it will be Valid....right?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:19:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295725#M89235</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-17T01:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295726#M89236</link>
      <description>&lt;P&gt;try &lt;CODE&gt;if(now() &amp;gt; class_plus_one_year, "Expired", "Valid")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:23:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295726#M89236</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-17T01:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295727#M89237</link>
      <description>&lt;P&gt;Wow. I guess I need to take a break. You have been right the whole time. I will drink a few beers on your name today.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:28:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295727#M89237</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2018-02-17T01:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295728#M89238</link>
      <description>&lt;P&gt;That might be a good option too!&lt;/P&gt;

&lt;P&gt;EDIT:&lt;/P&gt;

&lt;P&gt;Changed it to that and it also works.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:29:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295728#M89238</guid>
      <dc:creator>albinortiz</dc:creator>
      <dc:date>2018-02-17T01:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare dates for expiration purposes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295729#M89239</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ha ha ..&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2018 01:31:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-dates-for-expiration-purposes/m-p/295729#M89239</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-17T01:31:42Z</dc:date>
    </item>
  </channel>
</rss>

