Splunk Search

help on date field sorting

jip31
Motivator

hi

the field dv_sys_created_on is a field date

index="tutu" sourcetype="toto" 
| stats last(dv_sys_created_on) as Opened by ticket_id 

i tried to sort it like this but it doesnt works

| eval time = strftime(dv_sys_created_on, "%d-%m-%y %H:%M")
| sort - dv_sys_created_on

could you help please??

 

 

Labels (1)
Tags (1)
0 Karma
1 Solution

scelikok
SplunkTrust
SplunkTrust

Hi @jip31,

You are loosing the dv_sys_created_on field on stats command, you can sort like below;

index="tutu" sourcetype="toto" 
| stats last(dv_sys_created_on) as Opened by ticket_id 
| sort - Opened

Or if date field is string below should work better; assuming your date format is "%d-%m-%y %H:%M"

index="tutu" sourcetype="toto" 
| stats last(dv_sys_created_on) as Opened by ticket_id 
| eval time = strptime(Opened, "%d-%m-%y %H:%M")
| sort - time

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

What does "the field dv_sys_created_on is a field date" mean? Is it a string in a particular format representing a date? If so, you need to parse the string (the p in strptime means parse, the f in strftime means format) into an epoch datetime (a number) which you can then sort on (strptime, string to number; strftime, number to string)

| eval time = strptime(dv_sys_created_on, "%d-%m-%y %H:%M")
| sort - time

 

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @jip31,

You are loosing the dv_sys_created_on field on stats command, you can sort like below;

index="tutu" sourcetype="toto" 
| stats last(dv_sys_created_on) as Opened by ticket_id 
| sort - Opened

Or if date field is string below should work better; assuming your date format is "%d-%m-%y %H:%M"

index="tutu" sourcetype="toto" 
| stats last(dv_sys_created_on) as Opened by ticket_id 
| eval time = strptime(Opened, "%d-%m-%y %H:%M")
| sort - time

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...