<?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: Convert multiple fields as timestamp in csv file in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288456#M55123</link>
    <description>&lt;P&gt;If you want to define the event timestamp based on those fields at index time.&lt;BR /&gt;
Then you want to go on the "very first" forwarder monitoring those csv files, and setup a sourcetype with a definition .&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Data/Extractfieldsfromfileswithstructureddata"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Data/Extractfieldsfromfileswithstructureddata&lt;/A&gt;&lt;BR /&gt;
something like :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# in props.conf
[customcsv]
INDEXED_EXTRACTIONS=csv
TIMESTAMP_FIELDS = myfieldcolumnname
# or if the timestamp is over several columns
# TIMESTAMP_FIELDS = fieldhour,fielddate,fieldyear

 # in inputs.conf
[monitor://path/to/my/csv/file.csv]
sourcetype=customcsv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your events are already indexed, and you just want to generate a timestamp on the fly at search time from other fields.&lt;BR /&gt;
you can 1&lt;BR /&gt;
1 - extract the field (a rex command can do the trick) or maybe the field is already extracted as a string.&lt;BR /&gt;
2 - use an eval or convert function to parse it as a timestamp (and convert to epoch time or any format you want)&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Convert"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Convert&lt;/A&gt;&lt;BR /&gt;
and details on timeformat options &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/Data/Configuretimestamprecognition#Enhanced_strptime.28.29_support"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/Data/Configuretimestamprecognition#Enhanced_strptime.28.29_support&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example with fake event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval mytimefield="1:22:21:000PM" | eval mydatefield="Oct 2 2017" 
| eval mycombinedtime=mydatefield." ".mytimefield 
| convert TIMEFORMAT="%b %d %Y %I:%M:%S:%3N%p" mktime(mycombinedtime) AS myepochtime
| convert TIMEFORMAT="%Y/%m/%d %H:%M:%S.%3N %Z" ctime(myepochtime) AS anotherformatedtime 
| table mytimefield mydatefield mycombinedtime myepochtime anotherformatedtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will return something like :&lt;BR /&gt;
mytimefield 1:22:21:000PM&lt;BR /&gt;
mydatefield Oct 2 2017&lt;BR /&gt;
mycombinedtime  Oct 2 2017 1:22:21:000PM&lt;BR /&gt;
myepochtime 1506975741.000&lt;BR /&gt;
anotherformatedtime 2017/10/02 13:22:21.000 PDT&lt;BR /&gt;
(we converted to a more valid format, with 24h clock and timezone)&lt;/P&gt;</description>
    <pubDate>Thu, 05 Oct 2017 17:21:09 GMT</pubDate>
    <dc:creator>yannK</dc:creator>
    <dc:date>2017-10-05T17:21:09Z</dc:date>
    <item>
      <title>Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288455#M55122</link>
      <description>&lt;P&gt;I have a file with multiple fields as timestamp in the format of "Oct  2 2017  1:22:21:000PM". Can someone suggest how to convert it into timestamp so that i can perform logical operations on them? &lt;BR /&gt;
Can we update props/transforms command so that i can update it once and use the formats for all fields?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 15:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288455#M55122</guid>
      <dc:creator>chintan_shah</dc:creator>
      <dc:date>2017-10-05T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288456#M55123</link>
      <description>&lt;P&gt;If you want to define the event timestamp based on those fields at index time.&lt;BR /&gt;
Then you want to go on the "very first" forwarder monitoring those csv files, and setup a sourcetype with a definition .&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Data/Extractfieldsfromfileswithstructureddata"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Data/Extractfieldsfromfileswithstructureddata&lt;/A&gt;&lt;BR /&gt;
something like :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# in props.conf
[customcsv]
INDEXED_EXTRACTIONS=csv
TIMESTAMP_FIELDS = myfieldcolumnname
# or if the timestamp is over several columns
# TIMESTAMP_FIELDS = fieldhour,fielddate,fieldyear

 # in inputs.conf
[monitor://path/to/my/csv/file.csv]
sourcetype=customcsv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your events are already indexed, and you just want to generate a timestamp on the fly at search time from other fields.&lt;BR /&gt;
you can 1&lt;BR /&gt;
1 - extract the field (a rex command can do the trick) or maybe the field is already extracted as a string.&lt;BR /&gt;
2 - use an eval or convert function to parse it as a timestamp (and convert to epoch time or any format you want)&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Convert"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Convert&lt;/A&gt;&lt;BR /&gt;
and details on timeformat options &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/Data/Configuretimestamprecognition#Enhanced_strptime.28.29_support"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/Data/Configuretimestamprecognition#Enhanced_strptime.28.29_support&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example with fake event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval mytimefield="1:22:21:000PM" | eval mydatefield="Oct 2 2017" 
| eval mycombinedtime=mydatefield." ".mytimefield 
| convert TIMEFORMAT="%b %d %Y %I:%M:%S:%3N%p" mktime(mycombinedtime) AS myepochtime
| convert TIMEFORMAT="%Y/%m/%d %H:%M:%S.%3N %Z" ctime(myepochtime) AS anotherformatedtime 
| table mytimefield mydatefield mycombinedtime myepochtime anotherformatedtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will return something like :&lt;BR /&gt;
mytimefield 1:22:21:000PM&lt;BR /&gt;
mydatefield Oct 2 2017&lt;BR /&gt;
mycombinedtime  Oct 2 2017 1:22:21:000PM&lt;BR /&gt;
myepochtime 1506975741.000&lt;BR /&gt;
anotherformatedtime 2017/10/02 13:22:21.000 PDT&lt;BR /&gt;
(we converted to a more valid format, with 24h clock and timezone)&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 17:21:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288456#M55123</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2017-10-05T17:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288457#M55124</link>
      <description>&lt;P&gt;@yannK,&lt;/P&gt;

&lt;P&gt;Currently I am not able to convert this time "Oct  2 2017  1:22:21:000PM"  to epochtime? I am trying the below query but its not providing desired results&lt;BR /&gt;
convert timeformat="%b %d %Y %h:%M:%S:%3N%p" mktime(EFF_DT) as epochtime|table epochtime&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 17:34:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288457#M55124</guid>
      <dc:creator>chintan_shah</dc:creator>
      <dc:date>2017-10-05T17:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288458#M55125</link>
      <description>&lt;P&gt;Your hour is on a 12h clock, please use %I, instead of %H that is for 24 clock.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | stats count | eval EFF_DT="Oct 2 2017 1:22:21:000PM"
    | convert timeformat="%b %d %Y %I:%M:%S:%3N%P" mktime(EFF_DT) AS epochtime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 20:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288458#M55125</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2017-10-05T20:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288459#M55126</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1357"&gt;@yannK&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;Could you please tell me if its possible, to convert this epoch time in readable format in the same query so that i can use the string in Calculated Fields?&lt;BR /&gt;
I have below query which works fine but cant use it for creating calculated fields&lt;BR /&gt;
|convert mktime(EFF_DT) as epoch_EFF_DT timeformat="%b %d %Y %I:%M:%S:%3N%P"|eval EFF_DATE=strftime(epoch_EFF_DT,"%m/%d/%y %H:%M:%S")&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:07:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288459#M55126</guid>
      <dc:creator>chintan_shah</dc:creator>
      <dc:date>2020-09-29T16:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert multiple fields as timestamp in csv file</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288460#M55127</link>
      <description>&lt;P&gt;calculated fields requires "eval" commands&lt;BR /&gt;
hopefully, there is an eval equivalent to convert ctime or mktime -&amp;gt; strftime(X,Y) and strptime(X,Y)&lt;/P&gt;

&lt;P&gt;see &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/DateandTimeFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/DateandTimeFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 19:09:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Convert-multiple-fields-as-timestamp-in-csv-file/m-p/288460#M55127</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2017-10-06T19:09:45Z</dc:date>
    </item>
  </channel>
</rss>

