<?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: Extracting date from datetime field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138708#M38083</link>
    <description>&lt;P&gt;If your field is like "2015-02-08 02:15:24" there's no way that the format "%m/%d/%Y" could match that. For one thing, there are no slashes in your sample data, secondly I think the date fields are in the wrong order, thirdly, you will likely want to include the correct format string for parsing the time portion as well&lt;/P&gt;</description>
    <pubDate>Sun, 08 Feb 2015 20:30:04 GMT</pubDate>
    <dc:creator>acharlieh</dc:creator>
    <dc:date>2015-02-08T20:30:04Z</dc:date>
    <item>
      <title>Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138705#M38080</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;I have field named as "extract_datetime" and it has the following values;&lt;BR /&gt;
2015-02-08 02:15:24&lt;BR /&gt;
2015-02-08 02:18:39&lt;BR /&gt;
2015-02-07 01:38:11&lt;BR /&gt;
2015-01-28 11:01:00&lt;BR /&gt;
I want to extract the events which has current date. Lets say today is 8th Feb, i need the first 2 events only. Also there are few values where it has no values (blank). How can i avoid them as well.&lt;/P&gt;

&lt;P&gt;I tried using now() and strftime () but no avail. Any pointer in this case?&lt;/P&gt;</description>
      <pubDate>Sun, 08 Feb 2015 11:46:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138705#M38080</guid>
      <dc:creator>rogerbinny</dc:creator>
      <dc:date>2015-02-08T11:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138706#M38081</link>
      <description>&lt;P&gt;Assuming your field is being extracted as a string I would use something along the lines of &lt;CODE&gt;|where isnotnull(extract_datetime) and len(extract_datetime) &amp;gt; 0 and strptime(extract_datetime,"format string here, I'm on a cell phone so looking it up would be difficult") &amp;gt;= relative_time(now(),"@d")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Basically we keep those results where the field is a value, and we parse the field to a timestamp (strptime), and keep those only after midnight today (now() taken back to @d). Depending on the behavior of the strptime function, the first two clauses may be unnecessary, but I'd need to try things out on my Splunk instance to be sure.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Feb 2015 16:27:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138706#M38081</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-02-08T16:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138707#M38082</link>
      <description>&lt;P&gt;Thanks for your reply. But unfortunately it didn't work..&lt;BR /&gt;
I tried with the following option - no result(s) returned.&lt;BR /&gt;
      sourcetype="something"  extract_datetime= *&lt;BR /&gt;
     |  WHERE strptime(extract_datetime,"%m/%d/%Y") &amp;gt;= relative_time(now(),"@d") -- Replaced -1 &amp;amp; -2 with @d&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:52:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138707#M38082</guid>
      <dc:creator>rogerbinny</dc:creator>
      <dc:date>2020-09-28T18:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138708#M38083</link>
      <description>&lt;P&gt;If your field is like "2015-02-08 02:15:24" there's no way that the format "%m/%d/%Y" could match that. For one thing, there are no slashes in your sample data, secondly I think the date fields are in the wrong order, thirdly, you will likely want to include the correct format string for parsing the time portion as well&lt;/P&gt;</description>
      <pubDate>Sun, 08 Feb 2015 20:30:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138708#M38083</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-02-08T20:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138709#M38084</link>
      <description>&lt;P&gt;how about converting into a timestamp and then to a date format to compare against now().&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.. | where isnotnull(extract_datetime)| eval k=strptime(extract_datetime,"%Y-%m-%d %H:%M:%S") | eval m=strftime(now(),"%d-%m-%Y") | eval o=strftime(k,"%d-%m-%Y") | where o==m | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Feb 2015 23:26:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138709#M38084</guid>
      <dc:creator>ramdaspr</dc:creator>
      <dc:date>2015-02-08T23:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138710#M38085</link>
      <description>&lt;P&gt;Sorry, for the format.. Tried the following; but no avail.&lt;BR /&gt;
sourcetype="something" extract_datetime= *&lt;BR /&gt;
| WHERE strptime(extract_datetime,"%Y-%m-%d %H:%M:%S") &amp;gt;= relative_time(now(),"@d")&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:55:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138710#M38085</guid>
      <dc:creator>rogerbinny</dc:creator>
      <dc:date>2020-09-28T18:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138711#M38086</link>
      <description>&lt;P&gt;Sorry! Didn't work.. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Feb 2015 19:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138711#M38086</guid>
      <dc:creator>rogerbinny</dc:creator>
      <dc:date>2015-02-09T19:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138712#M38087</link>
      <description>&lt;P&gt;You can paste out the exact query you are trying? &lt;BR /&gt;
I tried the one above with my IIS logs to filter out specific days and it seems to work fine..&lt;/P&gt;</description>
      <pubDate>Mon, 09 Feb 2015 23:59:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138712#M38087</guid>
      <dc:creator>ramdaspr</dc:creator>
      <dc:date>2015-02-09T23:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138713#M38088</link>
      <description>&lt;P&gt;What is the format of the field? Is it a string or Date time value(epoch)? (run this and tell the output formatsourcetype="something" extract_datetime= * | table extract_datetime)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:55:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138713#M38088</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-28T18:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138714#M38089</link>
      <description>&lt;P&gt;What does the job inspector say? Does &lt;CODE&gt;sourcetype="something" extract_datetime=*&lt;/CODE&gt; return results? (Also I'm not sure if it matters or not but usually I've always written Splunk commands in lower case (e.g. &lt;CODE&gt;| where&lt;/CODE&gt; instead of &lt;CODE&gt;| WHERE&lt;/CODE&gt; )&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2015 00:34:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138714#M38089</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-02-10T00:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting date from datetime field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138715#M38090</link>
      <description>&lt;P&gt;Thank you guys for your help! Though my extract_datetime field has %Y-%m-%d %H:%M:%S but when i executed the below search, came to know it is only extracting %Y-%m-%d .&lt;/P&gt;

&lt;P&gt;sourcetype="something" extract_datetime= * | table extract_datetime&lt;/P&gt;

&lt;P&gt;Hence updated my search string as below and it works perfectly. Thanks again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;sourcetype="something" extract_datetime= *&lt;BR /&gt;
| WHERE strptime(extract_datetime,"%Y-%m-%d") &amp;gt;= relative_time(now(),"@d")&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:53:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-date-from-datetime-field/m-p/138715#M38090</guid>
      <dc:creator>rogerbinny</dc:creator>
      <dc:date>2020-09-28T18:53:05Z</dc:date>
    </item>
  </channel>
</rss>

