<?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: How to convert string to date? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321028#M95901</link>
    <description>&lt;P&gt;try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval Date="4/2/2018" 
 | eval timestamp=strftime(strptime(Date, "%m/%d/%Y"),"%m/%d/%Y") | eval _time=timestamp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Dec 2018 18:02:35 GMT</pubDate>
    <dc:creator>macadminrohit</dc:creator>
    <dc:date>2018-12-11T18:02:35Z</dc:date>
    <item>
      <title>How to convert string to date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321024#M95897</link>
      <description>&lt;P&gt;I have an existing column "Date" and I need to convert it from a string like 4/2/2018 to a date of 4/2/2018.&lt;/P&gt;

&lt;P&gt;I've tried some of the answers but none of them have worked so far.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 13:38:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321024#M95897</guid>
      <dc:creator>jimbolya11</dc:creator>
      <dc:date>2018-04-05T13:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string to date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321025#M95898</link>
      <description>&lt;P&gt;Here is how to do it in a search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Date="4/2/2018" 
| eval timestamp=strptime(Date, "%m/%d/%Y") 
| eval formattedTimestamp = strftime(timestamp,"%Y-%m-%dT%H:%M:%S.%Q")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is the "Date" field what you want to use as the timestamp of the event?  If so, timestamp recognition options -&amp;gt; &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Data/Configuretimestamprecognition"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Data/Configuretimestamprecognition&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 15:41:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321025#M95898</guid>
      <dc:creator>jconger</dc:creator>
      <dc:date>2018-04-05T15:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string to date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321026#M95899</link>
      <description>&lt;P&gt;Thanks...&lt;BR /&gt;
I must not be explaining my self correctly.&lt;/P&gt;

&lt;P&gt;I import a csv file.  Splunk automagically puts a _time field into the dataset.  This _time field is not what I want to use.  I want to use the Date field that was already in the csv during import.  Problem is that whole column is a string and not recognized as date.  Therefore I cannot specify date ranges in a search with it.  &lt;/P&gt;

&lt;P&gt;So far I've had some very limited luck with this string:&lt;/P&gt;

&lt;P&gt;index="dor_test" source="filename.csv" | eval Date=strptime(Date,"%m/%d/%Y") | fieldformat Date = strftime(Date, "%d-%b-%Y") | eval _time=Date&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 19:35:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321026#M95899</guid>
      <dc:creator>jimbolya11</dc:creator>
      <dc:date>2018-04-05T19:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string to date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321027#M95900</link>
      <description>&lt;P&gt;I had the same issue when trying to parse a date string from an input lookup. The following worked for me based on your example. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="dor_test" source="filename.csv" 
| convert mktime(Date) as Date timeformat="%m/%d/%Y"
| eval Date=strftime(Date,"%m/%d/%Y")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please note that the timeformat needs to match the incoming format. e.g. &lt;BR /&gt;
4/2/2018 = "%m/%d/%Y"&lt;BR /&gt;
4/2/18     = "%m/%d/%y"&lt;/P&gt;

&lt;P&gt;Hope that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 16:25:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321027#M95900</guid>
      <dc:creator>tpeterson2</dc:creator>
      <dc:date>2018-12-11T16:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string to date?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321028#M95901</link>
      <description>&lt;P&gt;try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval Date="4/2/2018" 
 | eval timestamp=strftime(strptime(Date, "%m/%d/%Y"),"%m/%d/%Y") | eval _time=timestamp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Dec 2018 18:02:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-to-date/m-p/321028#M95901</guid>
      <dc:creator>macadminrohit</dc:creator>
      <dc:date>2018-12-11T18:02:35Z</dc:date>
    </item>
  </channel>
</rss>

