Splunk Search

How do I add days taken from a field to a date field?

ZacEsa
Communicator

I have a field called "date"(2016-07-21) and a field called "countdown"(e.g. 30) which shows the number of days. How do I add the days to the date?

eval inputDate=strptime(date, "%Y-%m-%d") | eval expiring=relative_time(inputDate, "+30d@d") | eval expiring=strftime(expiring,"%Y-%m-%d")
0 Karma
1 Solution

javiergn
SplunkTrust
SplunkTrust

Probably the easiest way is to convert date to epoch in inputDate and then simply multiply countdown by the number of seconds in a day:

| eval inputDate = strptime(date, "%Y-%m-%d")
| eval expiring = inputDate  + countdown*86400
| eval expiring = strftime(expiring, "%Y-%m-%d")

View solution in original post

ZacEsa
Communicator

I meant to put "+countdown@d" instead of "+30d@d"

0 Karma

javiergn
SplunkTrust
SplunkTrust

Probably the easiest way is to convert date to epoch in inputDate and then simply multiply countdown by the number of seconds in a day:

| eval inputDate = strptime(date, "%Y-%m-%d")
| eval expiring = inputDate  + countdown*86400
| eval expiring = strftime(expiring, "%Y-%m-%d")

ZacEsa
Communicator

Works perfectly. Thanks! I was trying to find a Splunk feature that'll convert the days to epoch but, I wasn't thinking of just multiplying it. Haha.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...