Getting Data In

days information

roopeshetty
Path Finder

Hi Guys,

We have a field by name “Validity” which shows the validity date as below for different products;

Validity : Dec 19, 2021

Validity : Dec 11, 2022

Validity : Mar 14, 2023

Validity : Aug 24, 2021

Here we need to create a field by name “DaysRemaining” which will have the values as number of days left from today by deducting the current date (of host running splunk ) with that Validity date. We will run that query once in every day so that the Days remaining will change every day.

Can someone please help us with the splunk query?

0 Karma

woodcock
Esteemed Legend

Add this to the bottom of existing search:

... | eval Validity = strptime(Validity, "%b %d, %Y")
| fieldformat Validity = strftime(Validity, "%b %d, %Y")
| eval DaysRemaining = now() - Validity
| fieldformat DaysRemaining = tostring(DaysRemaining, "duration")
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @roopeshetty,
you have to convert dates in epochtime and then use eval to subtract:

your_search
| eval diff_days=(strptime(Validity,"%b %d,%Y")-now())/3600/24
| table Validity diff_days

Eventually, you can round.

Ciao.
Giuseppe

richgalloway
SplunkTrust
SplunkTrust

Finding the difference between timestamps requires first converting them to epoch (integer) form. Try this:

... | eval DaysRemaining = (now() - strptime(Validity, "%b %d, %Y")) / 86400
---
If this reply helps you, Karma would be appreciated.
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 ...