Dashboards & Visualizations

how can i extract date only from date field?

avneet26
Engager

hi , the format of the field is "errorOccuredOn":"2020-12-04+01:00" and i want to extract only the date i.e. only 2020-12-04 should be coming into the result. Let me know how this can be achieved.

0 Karma

avneet26
Engager

thanks it worked!

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @avneet26,

if you already have the field  errorOccuredOn and you need only to extract the date, you can use this regex:

| rex  field=errorOccuredOn "^(?<errorOccuredOn>\d+-\d+-\d+)"

If instead you have to extract the field from the raw data, you can use the following regex

| rex "\"errorOccuredOn\":\"(?<errorOccuredOn>\d+-\d+-\d+)"

that you can test at https://regex101.com/r/CRiDtQ/1

Sorry, but did you open a new question instead continue the old one?

Ciao.

Giuseppe

0 Karma

493669
Super Champion

@avneet26 you can use substr command-

|eval errorOccuredOn=substr(errorOccuredOn,1,10)
0 Karma
Get Updates on the Splunk Community!

Fall Into Learning with New Splunk Education Courses

Every month, Splunk Education releases new courses to help you branch out, strengthen your data science roots, ...

Super Optimize your Splunk Stats Searches: Unlocking the Power of tstats, TERM, and ...

By Martin Hettervik, Senior Consultant and Team Leader at Accelerate at Iver, Splunk MVPThe stats command is ...

How Splunk Observability Cloud Prevented a Major Payment Crisis in Minutes

Your bank's payment processing system is humming along during a busy afternoon, handling millions in hourly ...