Splunk Search

How to calculate date and int columns?

ositaumeozulu
Explorer

please i will be glad to get answer to this query

| eval  InT = if(((lastpickupdate + DaysOfARVRefil  + 28) > IIT), "Interrupted", "Active")

"lastpickupdate" and "IIT" columns are in date format, whereas "DaysOfARVRefil" is in Days(int)

please how do i successfully run this query 

thanks

osita

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @ositaumeozulu,

to make calculations between dates you have always to convert dates in epochtime,

I don't know what's the format of lastpickupdate and IIT, I suppose that it's "yyyy-mm-dd HH:MM:SS",

So you could run something like this:

| eval  InT = if(((strptime(lastpickupdate,"%Y-%m-%d %H:%M:%S") + DaysOfARVRefil*86400  + 28*86400) > strptime(IIT,"%Y-%m-%d %H:%M:%S")), "Interrupted", "Active")

Ciao.

Giuseppe

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Splunk cannot do much with dates in string format.  They should be converted into integers using the strptime function first.  Also, the number of days should be converted into seconds before it is added to a timestamp.

| eval lastpickupts = strptime(lastpickupdate, "<<format string>>")
| eval IITts = strptime(IIT, "<<format string>>")
| eval SecsOfARVRefil = (DaysOfARVRefil + 28) * 86400
| eval  InT = if(((lastpickupts + SecsOfARVRefil ) > IITts), "Interrupted", "Active")
---
If this reply helps you, Karma would be appreciated.
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @ositaumeozulu,

to make calculations between dates you have always to convert dates in epochtime,

I don't know what's the format of lastpickupdate and IIT, I suppose that it's "yyyy-mm-dd HH:MM:SS",

So you could run something like this:

| eval  InT = if(((strptime(lastpickupdate,"%Y-%m-%d %H:%M:%S") + DaysOfARVRefil*86400  + 28*86400) > strptime(IIT,"%Y-%m-%d %H:%M:%S")), "Interrupted", "Active")

Ciao.

Giuseppe

somesoni2
Revered Legend

Give this a try

| eval  InT = if((strptime(lastpickupdate,"%Y-%m-%d") + (DaysOfARVRefil  + 28)*86400) > strptime(IIT,"%Y-%m-%d"), "Interrupted", "Active")

 (assuming both lastpickupdate and IIT has date in string  and have format  "%Y-%m-%d". If they are different, adjust the time format accordingly)

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...