<?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: Eval formula to display dates till 31st december where start day is determined by a formula in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353937#M104756</link>
    <description>&lt;P&gt;Hey Rich&lt;/P&gt;

&lt;P&gt;I am actually calculating the difference between 2 dates where my year is dynamic based on the data.&lt;BR /&gt;
In return I need to whole date in the same format&lt;BR /&gt;
whole idea is to calculate the thanks giving day of the year also when I ll have thanks giving day as year-mon-day I need to print one week in the same format from that day.&lt;/P&gt;

&lt;P&gt;2016&lt;BR /&gt;
2015&lt;BR /&gt;
2017&lt;/P&gt;

&lt;P&gt;I tried this index="test" source="test" date=* mon=* year=* (STATDATE&amp;gt;=2016-11-22 AND STATDATE&amp;lt;=2016-11-30)  SITE=USA | eval day_c = strftime(_time,"%Y-%m-%d") | eval enddate= year+"-11-29"| eval startdate= year+"-11-24" | eval DiffInSecs = strptime(enddate, "%Y-%m-%d")-strptime(startdate, "%Y-%m-%d") | eval td = strftime(DiffInSecs, "%Y-%m-%d %A") | table day_c td &lt;/P&gt;

&lt;P&gt;but seems strftime doesnt work here &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 15:54:30 GMT</pubDate>
    <dc:creator>puneetkharband1</dc:creator>
    <dc:date>2020-09-29T15:54:30Z</dc:date>
    <item>
      <title>Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353935#M104754</link>
      <description>&lt;P&gt;Hey Everyone I am trying to write an eval when a user enter an year it should return a date&lt;BR /&gt;
formula works fine in excel DATE(F6,11,29)-WEEKDAY(DATE(F6,11,24))&lt;BR /&gt;
F6 is user input for an year.&lt;/P&gt;

&lt;P&gt;idea is to display the days from the days from thanksgiving to december 31st for any year I input.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:01:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353935#M104754</guid>
      <dc:creator>puneetkharband1</dc:creator>
      <dc:date>2017-09-21T18:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353936#M104755</link>
      <description>&lt;P&gt;It's not clear in what format you need this, or where you expect to place it.  Regardless of those difficulties, here's an option.&lt;/P&gt;

&lt;P&gt;If you can do it in SPL - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=12/25/2017 end=12/26/2017
| eval DaysToChristmas = round((starttime - now())/86400,0) 
| fields DaysToChristmas
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That would require updating the new gentimes once per year.  There's probably a workaround for that, but it's a 10 second fix once per year.  Note you should also confirm that number - you &lt;EM&gt;might&lt;/EM&gt; have to adjust it by + or - 1. &lt;/P&gt;

&lt;P&gt;The logic is simple: in this case, line 1 is just to create a fake event on Christmas Day, 2017. &lt;BR /&gt;
Line 2 first subtracts the current date and time &lt;CODE&gt;now()&lt;/CODE&gt; from the time the gentimes created &lt;CODE&gt;starttime&lt;/CODE&gt;, both of which are in seconds so we have to then divide by 86400 (the number of seconds in a day) to get days, then we round it to no decimals to get whole numbers.&lt;BR /&gt;
Line 3 is only display that one field.&lt;/P&gt;

&lt;P&gt;If you need to do this for a lot of events to see how far each is from Christmas, you can do it with similar logic in a regular search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mysearch ...
| eval DaysToChristmas = round((1514160001 - _time)/86400,0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Same logic, essentially.  Here I use the simpler "already converted to epoch format" number (I used &lt;A href="https://www.epochconverter.com/"&gt;Epoch Converter&lt;/A&gt;) and the event's &lt;CODE&gt;_time&lt;/CODE&gt;, but otherwise it's the same.&lt;/P&gt;

&lt;P&gt;Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:58:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353936#M104755</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2017-09-21T18:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353937#M104756</link>
      <description>&lt;P&gt;Hey Rich&lt;/P&gt;

&lt;P&gt;I am actually calculating the difference between 2 dates where my year is dynamic based on the data.&lt;BR /&gt;
In return I need to whole date in the same format&lt;BR /&gt;
whole idea is to calculate the thanks giving day of the year also when I ll have thanks giving day as year-mon-day I need to print one week in the same format from that day.&lt;/P&gt;

&lt;P&gt;2016&lt;BR /&gt;
2015&lt;BR /&gt;
2017&lt;/P&gt;

&lt;P&gt;I tried this index="test" source="test" date=* mon=* year=* (STATDATE&amp;gt;=2016-11-22 AND STATDATE&amp;lt;=2016-11-30)  SITE=USA | eval day_c = strftime(_time,"%Y-%m-%d") | eval enddate= year+"-11-29"| eval startdate= year+"-11-24" | eval DiffInSecs = strptime(enddate, "%Y-%m-%d")-strptime(startdate, "%Y-%m-%d") | eval td = strftime(DiffInSecs, "%Y-%m-%d %A") | table day_c td &lt;/P&gt;

&lt;P&gt;but seems strftime doesnt work here &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:54:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353937#M104756</guid>
      <dc:creator>puneetkharband1</dc:creator>
      <dc:date>2020-09-29T15:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353938#M104757</link>
      <description>&lt;P&gt;See this runanywhere search. Replace line1 with your search. What this does is for each year value, it first gets the thanksgiving day (getting 7day  range from Nov-22 and getting the Thursday) and then calculates difference between that and year end.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval year=mvrange(2012,2021) | table year | mvexpand year 
| eval thanksgivingrangestart=strptime(year."/11/22","%Y/%m/%d")  | eval date=mvrange(thanksgivingrangestart,thanksgivingrangestart+(86400*7),86400) | eval date=strftime(date,"%a %F") | eval thanksgivingday=mvfilter(match(date,"Thu")) | fields - date thanksgivingrangestart | eval dayFromThanksGivingToYearEnd=round((strptime(year."/12/31","%Y/%m/%d")-strptime(thanksgivingday,"%a %F"))/86400)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Sep 2017 22:09:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353938#M104757</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-09-21T22:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353939#M104758</link>
      <description>&lt;P&gt;Hey @puneetkharbanda, if they solved your problem, please don't forget to accept an answer! You can upvote posts as well. (Karma points will be awarded for either action.) Happy Splunking!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 00:16:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353939#M104758</guid>
      <dc:creator>lfedak_splunk</dc:creator>
      <dc:date>2017-09-22T00:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Eval formula to display dates till 31st december where start day is determined by a formula</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353940#M104759</link>
      <description>&lt;P&gt;thank you Somesh ...that will definitely bring me closer to what I am trying to do.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:19:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-formula-to-display-dates-till-31st-december-where-start-day/m-p/353940#M104759</guid>
      <dc:creator>puneetkharband1</dc:creator>
      <dc:date>2017-09-22T15:19:58Z</dc:date>
    </item>
  </channel>
</rss>

