Splunk Search

How to sort concatenated DATE&TIME field?

Ashwini008
Builder

Hi,

I have concatenated my DATE & TIME Field as below

| eval DATE&TIME=DATE." ".TIME

EXAMPLE:(%m/%d/%Y  %H:%S)

12/09/2017 23:28

01/27/2019 00:49

04/14/2018 23:42

How to sort my DATE&TIME field now .I want to show the latest date and time field at the beginning?

Any suggestions?

Thank you 

 

Labels (5)

inventsekar
SplunkTrust
SplunkTrust

Hi @Ashwini008 .. you have to convert to epoch and sort and then convert back to your format.  pls check the below SPL query. thanks.

 

...  | eval DATETIME=DATE." ".TIME 
| eval sortDate=strptime(DATETIME, "%m/%d/%Y %H:%S") | sort sortDate 
| eval DATETIME=strftime(SortDate, "%m/%d/%Y %H:%S")

 

 

(PS - i have given around 500+ karma points so far, received badge for that, if an answer helped you, a karma point would be nice!. we all should start "Learn, Give Back, Have Fun")

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !

Ashwini008
Builder

@inventsekar I tried your solution but it didn't work.The field was still in random order.

However i tried the below code and it worked for me

| eval EPOCHDATE=strptime(DATE,"%Y%m%d")
| sort -EPOCHDATE
| eval EPOCHTIME=strptime(TIME,"%H%M%S")
| sort -EPCOHTIME
| eval DATE=strftime(EPOCHDATE,"%m/%d/%Y")
| eval TIME=strftime(EPOCHTIME,"%H:%M")
| eval DATE&TIME=DATE." ".TIME

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...