<?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 can I convert my time format to epoch time? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318598#M95292</link>
    <description>&lt;P&gt;You are nearly right - I think your only problem is that you are quoting your field inside the &lt;CODE&gt;strptime&lt;/CODE&gt; - when you quote it Splunk treats is as a string with a value of "Duration" and tries to extract Hours, Minutes and Seconds from the &lt;STRONG&gt;word&lt;/STRONG&gt; "Duration", not the field.&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval "Duration"=strptime(Duration, "%Hh:%Mm:%Ss")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your "Duration" field ever has spaces, you can use &lt;EM&gt;single&lt;/EM&gt; quotes to quote it and it'll work.  See all three (No quotes, single quotes and regular quotes) in the below "run anywhere" example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval dur1="9h:42m:32s" 
| eval "edur1"=strptime("dur1", "%Hh:%Mm:%Ss")
| eval "edur2"=strptime('dur1', "%Hh:%Mm:%Ss")
| eval "edur3"=strptime(dur1, "%Hh:%Mm:%Ss")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notice it doesn't return "edur1".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; _time                      dur1           edur2                 edur3  
    2017-02-25 07:01:47     9h:42m:32s  1488037352.000000   1488037352.000000 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Feb 2017 13:08:06 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2017-02-25T13:08:06Z</dc:date>
    <item>
      <title>How can I convert my time format to epoch time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318596#M95290</link>
      <description>&lt;P&gt;Format i have in Splunk:- Duration as  9h:42m:32s&lt;/P&gt;

&lt;P&gt;I tried to use below search but it didn't worked.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval "Duration"=strptime("Duration", "%Hh:%Mm:%Ss")|
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in Advance&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 07:31:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318596#M95290</guid>
      <dc:creator>m7787580</dc:creator>
      <dc:date>2017-02-25T07:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert my time format to epoch time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318597#M95291</link>
      <description>&lt;P&gt;That value is not compatible with converting to epoch time because Splunk doesn't know when the time starts. The &lt;CODE&gt;strptime&lt;/CODE&gt; function expects you are sending it some form of wall clock time, not a duration. &lt;/P&gt;

&lt;P&gt;So, what is the start time, and what output would you really like to see: a clock time, or the number of seconds that duration represents (e.g., 34,952 seconds)?&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 12:35:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318597#M95291</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-02-25T12:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert my time format to epoch time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318598#M95292</link>
      <description>&lt;P&gt;You are nearly right - I think your only problem is that you are quoting your field inside the &lt;CODE&gt;strptime&lt;/CODE&gt; - when you quote it Splunk treats is as a string with a value of "Duration" and tries to extract Hours, Minutes and Seconds from the &lt;STRONG&gt;word&lt;/STRONG&gt; "Duration", not the field.&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval "Duration"=strptime(Duration, "%Hh:%Mm:%Ss")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your "Duration" field ever has spaces, you can use &lt;EM&gt;single&lt;/EM&gt; quotes to quote it and it'll work.  See all three (No quotes, single quotes and regular quotes) in the below "run anywhere" example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval dur1="9h:42m:32s" 
| eval "edur1"=strptime("dur1", "%Hh:%Mm:%Ss")
| eval "edur2"=strptime('dur1', "%Hh:%Mm:%Ss")
| eval "edur3"=strptime(dur1, "%Hh:%Mm:%Ss")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notice it doesn't return "edur1".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; _time                      dur1           edur2                 edur3  
    2017-02-25 07:01:47     9h:42m:32s  1488037352.000000   1488037352.000000 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2017 13:08:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318598#M95292</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2017-02-25T13:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert my time format to epoch time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318599#M95293</link>
      <description>&lt;P&gt;Do you want to convert your duration to epoch time or convert it to number of seconds? If it's later, try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search |  eval Duration=replace(Duration,"[hms]","")  | convert dur2sec(Duration) as Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your current search |  eval Duration=strptime(Duration,"%Hh:%Mm:%Ss")-relative_time(now(),"@d") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2017 20:16:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-my-time-format-to-epoch-time/m-p/318599#M95293</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-25T20:16:35Z</dc:date>
    </item>
  </channel>
</rss>

