Getting Data In

Changing date format and find date difference in days?

dtccsundar
Path Finder

Hi ,

I want to change the date format and find difference in days from current day .

Date format i  have now is ,

Timestamp

10/31/2022 1:28:20 PM

index=s sourcetype=Resources|fillnull
| eval Timestamp=strftime(strptime('Timestamp',"%m/%d/%Y"),"%Y-%m-%d") | eval diff=now()-Timestamp|table Name _time Timestamp diff

Here i am not getting the diff field populated with difference in number of days.It shows as blank .The date format i expect is %Y-%m-%d for timestamp  column.

Please help me to achieve this .

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

In order to do arithmetic on time values they need to be in epoch form so save the epoch time returned by strptime() so you can subtract it from now() 

index=s sourcetype=Resources
|fillnull
| eval time=strptime('Timestamp',"%m/%d/%Y")
| eval Timestamp=strftime(time,"%Y-%m-%d")  
| eval diff=now()-time
|table Name _time Timestamp diff

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

In order to do arithmetic on time values they need to be in epoch form so save the epoch time returned by strptime() so you can subtract it from now() 

index=s sourcetype=Resources
|fillnull
| eval time=strptime('Timestamp',"%m/%d/%Y")
| eval Timestamp=strftime(time,"%Y-%m-%d")  
| eval diff=now()-time
|table Name _time Timestamp diff

dtccsundar
Path Finder

Thank you .It worked as expected .

Tags (1)
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 ...