<?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 Why is strptime and strftime command not working as expected? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-strptime-and-strftime-command-not-working-as-expected/m-p/451834#M127941</link>
    <description>&lt;P&gt;I have two "Survey Type" - 'a' and 'b' and I need to display their count based on the"Survey Complete" data.&lt;BR /&gt;
Note - The Survey Complete date is in the format MM/DD/YYYY HH:MM format but I need to display it as MM-YYYY format . How do I reframe the below query to get the expected output mentioned above.&lt;/P&gt;

&lt;P&gt;index="xyz" &lt;BR /&gt;
| eval FIELD=strptime("Survey Complete","%m/%d/%Y %H:%M") &lt;BR /&gt;
| eval DesiredTime=strftime(FIELD,"%Y-%m-%d")&lt;BR /&gt;
| chart count over "Survey Complete" by "Survey Type"&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2019 09:27:43 GMT</pubDate>
    <dc:creator>monyathomas</dc:creator>
    <dc:date>2019-06-28T09:27:43Z</dc:date>
    <item>
      <title>Why is strptime and strftime command not working as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-strptime-and-strftime-command-not-working-as-expected/m-p/451834#M127941</link>
      <description>&lt;P&gt;I have two "Survey Type" - 'a' and 'b' and I need to display their count based on the"Survey Complete" data.&lt;BR /&gt;
Note - The Survey Complete date is in the format MM/DD/YYYY HH:MM format but I need to display it as MM-YYYY format . How do I reframe the below query to get the expected output mentioned above.&lt;/P&gt;

&lt;P&gt;index="xyz" &lt;BR /&gt;
| eval FIELD=strptime("Survey Complete","%m/%d/%Y %H:%M") &lt;BR /&gt;
| eval DesiredTime=strftime(FIELD,"%Y-%m-%d")&lt;BR /&gt;
| chart count over "Survey Complete" by "Survey Type"&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 09:27:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-strptime-and-strftime-command-not-working-as-expected/m-p/451834#M127941</guid>
      <dc:creator>monyathomas</dc:creator>
      <dc:date>2019-06-28T09:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is strptime and strftime command not working as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-strptime-and-strftime-command-not-working-as-expected/m-p/451835#M127942</link>
      <description>&lt;P&gt;You don't say what unexpected output you get, but your query doesn't match your question so that could be it.&lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xyz" 
| eval FIELD=strptime("Survey Complete","%m/%d/%Y %H:%M") 
| eval DesiredTime=strftime(FIELD,"%m-%Y")
| chart count over "Survey Complete" by "Survey Type"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also use a single &lt;CODE&gt;eval&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="xyz" 
| eval DesiredTime=strftime(strptime("Survey Complete","%m/%d/%Y %H:%M"), "%m-%Y)
| chart count over "Survey Complete" by "Survey Type"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 12:29:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-strptime-and-strftime-command-not-working-as-expected/m-p/451835#M127942</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-06-28T12:29:42Z</dc:date>
    </item>
  </channel>
</rss>

