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!

Index This | When is October more than just the tenth month?

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

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...