Splunk Search

How to extract the month from date field in string?

srinadh
New Member

I have a date field in a string with the format as mn/day/year. I need to extract the month from the same. Can someone help on this issue?

0 Karma

chrishartsock
Path Finder

The best way I have found to do this is convert field to epoch time, then just pull the month out of that. For example:

| eval epochField=strptime(field, "%m/%d/%Y")
| eval month=strftime(epochField, "%B")

The syntax will vary somewhat based on the exact format of the date and the exact format you want the month in. Refer to this document: http://docs.splunk.com/Documentation/Splunk/6.6.0/SearchReference/Commontimeformatvariables

0 Karma

cmerriman
Super Champion

you can combine them into one eval, as well.

| eval month=strftime(strptime(field, "%m/%d/%y"), "%B")
0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=YourFieldHere "(^?<Month>[^\/]+)"
0 Karma
Get Updates on the Splunk Community!

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had 3 releases of new security content via the Enterprise Security ...

Archived Metrics Now Available for APAC and EMEA realms

We’re excited to announce the launch of Archived Metrics in Splunk Infrastructure Monitoring for our customers ...