<?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: strftime and strptime functions are not working in search queries in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271391#M176784</link>
    <description>&lt;P&gt;What are the original values of your field &lt;CODE&gt;Last_Modified_Date&lt;/CODE&gt;? Is it a Unix timestamp or some other date format?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;strftime&lt;/CODE&gt; requests the time field to be a Unix timestamp, otherwise it does not know how to transform the date. &lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2016 11:30:49 GMT</pubDate>
    <dc:creator>DMohn</dc:creator>
    <dc:date>2016-09-13T11:30:49Z</dc:date>
    <item>
      <title>strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271386#M176779</link>
      <description>&lt;P&gt;I have multiple time fields in my db like Reported Date, Last Modified Date, Responded Date.. If  I apply strftime/strptime functions on that it is not working someone plz  tell me how to do that.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 11:04:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271386#M176779</guid>
      <dc:creator>ygkr</dc:creator>
      <dc:date>2016-09-09T11:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271387#M176780</link>
      <description>&lt;P&gt;I'm guessing your fields are literally called &lt;CODE&gt;Reported Date&lt;/CODE&gt;, and you tried &lt;CODE&gt;strptime(Reported Date, "%...")&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;If so you will need to enclose the field names in single quotes: &lt;CODE&gt;strptime('Reported Date', "%...")&lt;/CODE&gt;&lt;BR /&gt;
Whenever possible you should use field names with alphanumeric and underscore characters to ease &lt;CODE&gt;eval&lt;/CODE&gt; use. For a worse example, &lt;CODE&gt;Report+Date&lt;/CODE&gt; would be a valid field name... but &lt;CODE&gt;eval&lt;/CODE&gt; would interpret that as "Report field plus Date field" without the single quotes.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2016 12:33:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271387#M176780</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-09-09T12:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271388#M176781</link>
      <description>&lt;P&gt;Thanks for the response martin... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
I tried with single quotes even though my datetime fields are not working with strftime and strptime functions as I expected...!!&lt;BR /&gt;
It is working with only &lt;STRONG&gt;_time&lt;/STRONG&gt; field but my requirement is to work with all the datetime fields in the given data like('Reported Date', 'Last_Modified_Date' and 'Last_Resolved_Date'&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:55:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271388#M176781</guid>
      <dc:creator>ygkr</dc:creator>
      <dc:date>2020-09-29T10:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271389#M176782</link>
      <description>&lt;P&gt;Well, I could keep guessing different things that you may or may not be doing wrong... or you could supply more information. What do those fields look like? What searches have you tried that failed? What does a failed result look like?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 22:19:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271389#M176782</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-09-12T22:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271390#M176783</link>
      <description>&lt;P&gt;source="TDA_APA_Excel Data.csv" host="CDC1-D-6QKN7BS" index="test" sourcetype="test" &lt;BR /&gt;
| eval time = strftime(_time, "%Y")&lt;BR /&gt;
| dedup time&lt;BR /&gt;
| table time&lt;/P&gt;

&lt;P&gt;O/P&lt;BR /&gt;
&lt;STRONG&gt;time↕ &lt;BR /&gt;
2016&lt;BR /&gt;&lt;BR /&gt;
2015&lt;BR /&gt;&lt;BR /&gt;
2014&lt;BR /&gt;&lt;BR /&gt;
2013&lt;BR /&gt;&lt;BR /&gt;
2012&lt;BR /&gt;&lt;BR /&gt;
2011&lt;/STRONG&gt;  &lt;/P&gt;

&lt;P&gt;This is wt I tried to get the same output as I got for "_time" field as shown above.&lt;/P&gt;

&lt;P&gt;source="TDA_APA_Excel Data.csv" host="CDC1-D-6QKN7BS" index="test" sourcetype="test" &lt;BR /&gt;
| eval time = strftime('Last_Modified_Date', "%Y")&lt;BR /&gt;
| dedup time&lt;BR /&gt;
| table time&lt;/P&gt;

&lt;P&gt;Obtained O/P: No results found.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:57:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271390#M176783</guid>
      <dc:creator>ygkr</dc:creator>
      <dc:date>2020-09-29T10:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271391#M176784</link>
      <description>&lt;P&gt;What are the original values of your field &lt;CODE&gt;Last_Modified_Date&lt;/CODE&gt;? Is it a Unix timestamp or some other date format?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;strftime&lt;/CODE&gt; requests the time field to be a Unix timestamp, otherwise it does not know how to transform the date. &lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 11:30:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271391#M176784</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2016-09-13T11:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271392#M176785</link>
      <description>&lt;P&gt;Hi DMohn thanks for the response,...&lt;BR /&gt;
The dataformat for the field &lt;STRONG&gt;Last_Modified_Date&lt;/STRONG&gt; is &lt;STRONG&gt;DateTime&lt;/STRONG&gt;.&lt;BR /&gt;
It is not unix timestamp... plz let me knw hw to convert that field to unix timestamp dataformat????&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:58:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271392#M176785</guid>
      <dc:creator>ygkr</dc:creator>
      <dc:date>2020-09-29T10:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271393#M176786</link>
      <description>&lt;P&gt;Taking the information from your last comment (&lt;STRONG&gt;Last_Modified_Date&lt;/STRONG&gt; being SQL DateTime format) you will have to convert this date into a Unix Timestamp by using &lt;CODE&gt;strptime&lt;/CODE&gt; before being able to use &lt;CODE&gt;strftime&lt;/CODE&gt; again.&lt;/P&gt;

&lt;P&gt;If your &lt;STRONG&gt;Last_Modified_Date&lt;/STRONG&gt; looks like 2016-09-01 10:00:00 (YYYY-MM-DD HH:MM:SS) you may use the following conversion to only have the year (I assume thats what you want):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your_base_search | eval year=strftime(strptime(Last_Modified_Date,"%Y-%m-%d %H:%M:%S"),"%Y")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may refer to &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables&lt;/A&gt; for more information on the date and time variables of &lt;CODE&gt;strptime&lt;/CODE&gt;and &lt;CODE&gt;strftime&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:00:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271393#M176786</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2020-09-29T11:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: strftime and strptime functions are not working in search queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271394#M176787</link>
      <description>&lt;P&gt;Thanq DMohn.... Its working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 09:12:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/strftime-and-strptime-functions-are-not-working-in-search/m-p/271394#M176787</guid>
      <dc:creator>ygkr</dc:creator>
      <dc:date>2016-09-14T09:12:49Z</dc:date>
    </item>
  </channel>
</rss>

