<?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: String to Date Time in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217530#M98853</link>
    <description>&lt;P&gt;First, you need to convert the string to epoch time using the &lt;CODE&gt;strptime&lt;/CODE&gt; command &amp;amp; then find the difference.. try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval opened_epoch=strptime(Opened, "%-m/%d/%Y %H:%M) | eval resolved_epoch=strptime(Resolved, "%-m/%d/%Y %-H:%M) | eval duration=tostring(resolved_epoch-opened_epoch, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Jun 2016 17:08:53 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-06-23T17:08:53Z</dc:date>
    <item>
      <title>String to Date Time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217529#M98852</link>
      <description>&lt;P&gt;I am new to splunk and currently trying to get the date and time difference (Opened vs Resolved) for an incident. &lt;BR /&gt;
Based on the field type Opened &amp;amp; Resolved are string type and what should I do? I have gone to multiple answers but not able to figure out the solution. Please help.&lt;/P&gt;

&lt;P&gt;Below is the example of my selected fields&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Assigned to = Arjay Torreliza
Category = Alert
Number = INC0975300
Opened = 5/31/2016 22:43
Resolved = 6/1/2016 9:49
host = prd-p-ttsrqrml973d
source = incident.csv
sourcetype = csv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2016 03:48:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217529#M98852</guid>
      <dc:creator>dhiraj027in</dc:creator>
      <dc:date>2016-06-23T03:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date Time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217530#M98853</link>
      <description>&lt;P&gt;First, you need to convert the string to epoch time using the &lt;CODE&gt;strptime&lt;/CODE&gt; command &amp;amp; then find the difference.. try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval opened_epoch=strptime(Opened, "%-m/%d/%Y %H:%M) | eval resolved_epoch=strptime(Resolved, "%-m/%d/%Y %-H:%M) | eval duration=tostring(resolved_epoch-opened_epoch, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2016 17:08:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217530#M98853</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-23T17:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date Time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217531#M98854</link>
      <description>&lt;P&gt;Great. This works but the duration is not exactly what I am looking for. Is this possible?&lt;/P&gt;

&lt;P&gt;Current output (this shows 6 days, 23 hours &amp;amp; 23 seconds)&lt;BR /&gt;
6+23:23:00.000000 &lt;/P&gt;

&lt;P&gt;What I am looking for (167 hours and 23 seconds)&lt;BR /&gt;
167:23:00.000000&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 18:00:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217531#M98854</guid>
      <dc:creator>dhiraj027in</dc:creator>
      <dc:date>2016-06-23T18:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date Time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217532#M98855</link>
      <description>&lt;P&gt;Add this to the end&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=z "(?&amp;lt;d&amp;gt;\d{0,2})\+?(?&amp;lt;h&amp;gt;\d{2})(?&amp;lt;ms&amp;gt;:\d{2}:\d{2})" | eval d=if(len(d)=0, 0, d) | eval duration=(d*24+h).ms 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:00:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217532#M98855</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-23T20:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date Time</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217533#M98856</link>
      <description>&lt;P&gt;I used the above and integrated with my query. I am not getting any output for "duration". Should I change anything here?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="incidents_stores_wisp" date_year="2016" Category="Alert" | eval opened_epoch=strptime(Opened, "%m/%d/%Y %H:%M") | eval resolved_epoch=strptime(Resolved, "%m/%d/%Y %H:%M") | eval duration=tostring(resolved_epoch-opened_epoch, "duration") | rex field=z "(?\d{0,2})\+?(?\d{2})(?:\d{2}:\d{2})" | eval d=if(len(d)=0, 0, d) | eval duration=(d*24+h).ms | table Number "Assigned to" "Short description" Opened Resolved duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2016 23:29:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/String-to-Date-Time/m-p/217533#M98856</guid>
      <dc:creator>dhiraj027in</dc:creator>
      <dc:date>2016-06-23T23:29:01Z</dc:date>
    </item>
  </channel>
</rss>

