Dashboards & Visualizations

How to extract Date and Time from the raw logs

aditsss
Motivator

Hi Everyone,

Below is my data( raw logs)

pod_name=node-fdzz message=2020-09-25 21:09:33.969 ERROR [node,00e,4deca,false]67 --- [r-84-548] c.r.Resolver 

How do I extract Date and time 2020-09-25 21:09:33.969 from the above log data?

Can anyone guide me on this.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This regex will extract the datetime

"message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"
0 Karma

aditsss
Motivator

@ITWhisperer 

 

I tried like below . Not able to get any result

Where I am going wrong!

index=abc ns=sigh nodeException node="*" Id=* |rex field="message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Ideally, this extract should be done at indexing time

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime
0 Karma

aditsss
Motivator

@ITWhisperer 

 

Thank you once again . It works exactly the way I want.

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

  &#x1f680; 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 ...