Splunk Search

Help to convert a unix time

jip31
Motivator

Hi

I use a | stats min(_time) as time_min stats max(_time) as time_max command in my search

The time is displayed in Unix format

Example :

Time_min=1688019886.761

Time-max=1690461727.136

I have added an eval time=strftime(_time, "%d-%m-%Y %H:%M" before the stats in order to convert the time but the result is sometimes strange because the max time is older than the min time

How to convert the time properly please?

Tags (1)
0 Karma
1 Solution

jotne
Builder

You need your search above and it needs to contain the _time field.   Can you post your full SPL search?

 

<your search>
| stats min(_time) as time_min max(_time) as time_max 
| convert ctime(time_min)
| convert ctime(time_max)

 

 

This should work with all Splunk installation:

index=_internal
| stats min(_time) as time_min max(_time) as time_max 
| convert ctime(time_min)
| convert ctime(time_max)

View solution in original post

0 Karma

jotne
Builder

If you like a custom format, yes, then your need to use eval and not convert.

PS if you can accept the answer it would be fine 🙂

0 Karma

jotne
Builder

You need your search above and it needs to contain the _time field.   Can you post your full SPL search?

 

<your search>
| stats min(_time) as time_min max(_time) as time_max 
| convert ctime(time_min)
| convert ctime(time_max)

 

 

This should work with all Splunk installation:

index=_internal
| stats min(_time) as time_min max(_time) as time_max 
| convert ctime(time_min)
| convert ctime(time_max)
0 Karma

jotne
Builder

Try this:

 

| stats min(_time) as time_min max(_time) as time_max 
| convert ctime(time_min)
| convert ctime(time_max)

 

 

 

0 Karma

jip31
Motivator

Tha.ks it works

And now if i want to format the time i need to do an eval _time?

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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 ...