<?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: Subtraction of X days from a date in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565477#M197030</link>
    <description>&lt;P&gt;Well, yes, and no &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'd advise against formating time to text whenever possible. If possible - keep the time as unix timestamp, only format it on output with | fieldformat. That way any time manipulation is much easier (you just add/substract appropriate number of seconds) without the need of recalculating the date to/from the string representation.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 11:55:15 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2021-09-01T11:55:15Z</dc:date>
    <item>
      <title>Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565456#M197020</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Probably very simple question but I just tangled myself in the logic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create 2 fields, one with today's date so I have that one&lt;BR /&gt;| eval today_date=strftime(now(),"%B %d, %Y")&lt;BR /&gt;&lt;BR /&gt;and the second one where I want to subtract 30days from that date.&lt;BR /&gt;&lt;BR /&gt;How do I get about it?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:48:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565456#M197020</guid>
      <dc:creator>klaudiac</dc:creator>
      <dc:date>2021-09-01T10:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565459#M197022</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223748"&gt;@klaudiac&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;to work ondates, you have to work using epochtime.&lt;/P&gt;&lt;P&gt;In other words you have to subtract from now() the seconds of 30 days (3600*24*30):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval today_date=strftime(now(),"%B %d, %Y"), 30_days_past_date=strftime(now()-2592000,"%B %d, %Y")&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:52:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565459#M197022</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-09-01T10:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565461#M197023</link>
      <description>&lt;P&gt;That makes sense. I was trying to do&amp;nbsp;| eval 30days_date=strftime((now(),"-30d@d")) and was wondering why it isn't working.&lt;/P&gt;&lt;P&gt;Thanks very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:04:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565461#M197023</guid>
      <dc:creator>klaudiac</dc:creator>
      <dc:date>2021-09-01T11:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565464#M197025</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223748"&gt;@klaudiac&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you can do also in another way:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval 30_days_past_date=relative_time(now(),"-30d@d")&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;P.S.: if this answer solves your need, please accept it for the other people of Community and Karma Points are appreciated;-)&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:13:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565464#M197025</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-09-01T11:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565473#M197028</link>
      <description>&lt;P&gt;Cool, thanks very much for that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And one more question&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;before I let you go &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I want to have a fixed date, e.g. have 1st of September as a constant date, and then do a difference between today and that 1st of Sept, how should I formulate the eval command?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because my&amp;nbsp;| eval today_date=strftime(now(),"%B %d, %Y") will be dynamic so that's fine, but how do i calculate the difference between that fixed date and my dynamic today_date?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:41:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565473#M197028</guid>
      <dc:creator>klaudiac</dc:creator>
      <dc:date>2021-09-01T11:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565476#M197029</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223748"&gt;@klaudiac&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you can define a fixed date using eval, but remember that to manipulate dates, you have always to work using epochtime, so try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval fixed_date="01/09/2021"
| eval epoch_fixed_date=strptime(fixed_date,"%d/%m/%Y")
| eval diff=epoch_fixed_date-now()&lt;/LI-CODE&gt;&lt;P&gt;then if you want to display this difference in a different format than seconds, you can add:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval difference=tostring(diff,"duration")&lt;/LI-CODE&gt;&lt;P&gt;Ciao and happy splunking.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:52:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565476#M197029</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-09-01T11:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction of X days from a date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565477#M197030</link>
      <description>&lt;P&gt;Well, yes, and no &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'd advise against formating time to text whenever possible. If possible - keep the time as unix timestamp, only format it on output with | fieldformat. That way any time manipulation is much easier (you just add/substract appropriate number of seconds) without the need of recalculating the date to/from the string representation.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:55:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtraction-of-X-days-from-a-date/m-p/565477#M197030</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-09-01T11:55:15Z</dc:date>
    </item>
  </channel>
</rss>

