Splunk Search

convert date to readable format

katesplunk
Explorer

Experts,
Time of the log is appended in my source file name ... I want it to be converted into a human readable format and i prefer assigning the same to a field . lets say new_time.. Hope u can help me...
Sample file name
...... 20130124 ......... file.txt
...... 20121229.......... file.txt
Thanks
Katrine

Tags (2)
0 Karma

yannK
Splunk Employee
Splunk Employee

first, extract the date from the source.

source=*mysource* | rex field=source "(?<_date_>\d{8})" | table _date_

see http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex

second convert the date using your format of choice .
mysearch | convert TIMEFORMAT="%Y-%m-%d" ctime(_date_) AS date

see http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert

smolcj
Builder

have the same query, but i dont want it to be in readable format as i am using this time for sorting my field entries..
How to convert the date in the above format to epoch time?
201303140216
yyyymmddHHMM
here hour and minute is in 12 hours clock, so the time may be 02:16PM
tried converting it using
time=strptime(mytime,"%Y%m%d%I%M")
not seems to be working properly...
please help

0 Karma

Drainy
Champion

What did you try exactly?

katesplunk
Explorer

date is in the format yyyymmdd so output should be 24-01-2013.. but result obtained is something else.. tried changing time date variables

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...