Splunk Search

Work with dates outside of timestamp

gnoellbn
Explorer

Hello,

I'm trying to keep only results where the date in a field (unix time) is earlier than the previous month.

I've tried a couple of searches but I can't figure it out, this is the latest I found :

| where recentTime=relative_time(now(), "-mon") 

Thanks 😉

Tags (2)
0 Karma
1 Solution

lguinn2
Legend

Try

| where recentTime < relative_time(now(),"-mon@mon")

or

| where recentTime < relative_time(now(),"-2mon@mon")

If the current month is September, the first clause will select only events prior to 1-Sep. The second will select only events prior to 1-Aug

View solution in original post

lguinn2
Legend

Try

| where recentTime < relative_time(now(),"-mon@mon")

or

| where recentTime < relative_time(now(),"-2mon@mon")

If the current month is September, the first clause will select only events prior to 1-Sep. The second will select only events prior to 1-Aug

tweekes
New Member

Thank You!
You put me on the correct path. I needed the following.
sourcetype=qps | where strptime(last_updt_dtm,"%Y-%m-%d %H:%M:%S") < relative_time(now(),"-2mon@mon")

0 Karma

lguinn2
Legend

You can't put a calculation like last_updt_dtm < relative_time(now(),"-2mon@mon") in the search string. Note in my answer that this was part of the where command. So your first search could be

sourcetype=qps | where last_updt_dtm < relative_time(now(),"-2mon@mon")

0 Karma

tweekes
New Member

I have 9999 events where the earliest one is:
last_updt_dtm = 2010-09-30 17:43:48

sourcetype=qps _time < now()

Returns all 9999

The following two searches fail
sourcetype=qps last_updt_dtm < relative_time(now(),"-2mon@mon")
sourcetype=qps _time < relative_time(now(),"-2mon@mon")

Any help would be much appreciated!
Thanks!

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...