Splunk Search

How to convert epoch time to a readable format?

asewell97
New Member

I'm currently creating a dashboard and need to put the time of an event into a readable format as I currently see a number such as: 1571187604872

The search I am running is:

index=BLAH Field1="BLAHBLAH" 
|eval Time=strftime(Field2, "%Y/%m/%d %H:%M")
|table Time Field3 Field4 Field5 Field6

This search doesn't gives me a readable time but the time isn't correct as the date are all the same with the year being 9999. Can somebody give me some guidance on how to correct this please?

0 Karma

woodcock
Esteemed Legend

Sometimes the field is milliseconds, not seconds; try this:

index=BLAH Field1="BLAHBLAH"
| eval Time=strftime(tonumber(Field2) / 1000, "%Y/%m/%d %H:%M")
| table Time Field3 Field4 Field5 Field6
0 Karma

adonio
Ultra Champion

looks like you epoch has milliseconds in it ... but doesnt have the dot . in place
1571187604872 should be 1571187604.872
try this website:
https://www.epochconverter.com/
then try in splunk:

 | makeresults count=1
    | eval data = "1571187604872 1571187614872 1571187605872 1571187601000"
    | makemv data
    | mvexpand data
    | eval bad_time = strftime(data, "%Y/%m/%d %H:%M")
    | eval fix_mili = tonumber(data / 1000)
    | eval good_time = strftime(fix_mili, "%Y/%m/%d %H:%M:%S")

hope it helps

Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...