Splunk Search

Convert years month days to Days

figuringthings
New Member

Hey,

Can anyone help me convert Age to Days? Have trouble parsing and calculating.

 

Sample Data

Age

2 years 3 months 2 days

3 months 4 days

2 days

 

I want to have a column with converted values to just days. Dont want exact days. Year could be 365 and month could be 30.

Age, d_age

2 years 3 months 2 days, 457

3 months 4 days, 94

2 days, 2

Labels (2)
Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults
| eval _raw="2 years 3 months 2 days
3 months 4 days
2 days"
| multikv noheader=t 
| fields _raw
| rex "(((?<years>\d+)\syears?\s)?(?<months>\d+)\smonths?\s)?(?<days>\d+)\sdays?"
| fillnull value=0
| eval d_age=(years * 365)+(months * 30)+days
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Here is how

| makeresults
| eval Age=split("2 years 3 months 2 days,3 months 4 days,2 days", ",")
| mvexpand Age
| rex field=Age "((?<years>\d+)\s+years[^\d]*)?((?<months>\d+)\s+months[^\d]*)?((?<days>\d+)\s+days)?"
| fillnull years months days
| eval d_age=(years*365)+(months*30)+days
| table Age d_age years months days

I assume your 457 for the first was assuming 1 year...

 

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...