Getting Data In

Convert String to Date then display Latest Date

JoshuaJohn
Contributor

I have this search

|inputlookup fdss2017.csv|search "SCCM Last Policy Request"=* |fields "SCCM Last Policy Request"

Which gives me results like this:

SCCM Last Policy Request
3/28/2017 19:25
3/13/2017 15:51
3/13/2017 16:31
3/21/2017 13:59
3/19/2017 0:02
1/10/2017 18:01
4/3/2017 13:21
3/24/2017 15:47
3/2/2017 6:35
3/17/2017 23:52
3/28/2017 15:00
3/20/2017 20:48
3/27/2017 13:47

I want my search to convert all of the dates into actual dates (MM/DD/YYYY) then to grab the latest date and only display that date/time.

Tags (2)
0 Karma

woodcock
Esteemed Legend

Like this:

|inputlookup fdss2017.csv|search "SCCM Last Policy Request"=* 
| fields "SCCM Last Policy Request"
| eval SCCM_Last_Policy_Request = strptime("SCCM Last Policy Request", "%m/%d/%Y %H:%M")
| sort 1 - SCCM_Last_Policy_Request
0 Karma

somesoni2
Revered Legend

Try like this

|inputlookup fdss2017.csv|search "SCCM Last Policy Request"=* |fields "SCCM Last Policy Request" | eval Date=strptime(mvindex(split('SCCM Last Policy Request'," "),0),"%m/%d/%Y") | eventstats max(Date) as max | where Date=max

This will give you records with max/latest date value. If there are multiple records in that date it'll show all those.

If you're looking for just single latest records, considering both date and time, try like this

 |inputlookup fdss2017.csv|search "SCCM Last Policy Request"=* |fields "SCCM Last Policy Request" | eval Date=strptime('SCCM Last Policy Request',"%m/%d/%Y %H:%M") | sort 1 -Date | fields "SCCM Last Policy Request" 

OR

 |inputlookup fdss2017.csv|search "SCCM Last Policy Request"=* |fields "SCCM Last Policy Request" | eval Date=strptime('SCCM Last Policy Request',"%m/%d/%Y %H:%M") | stats max(Date) as "SCCM Last Policy Request" | eval "SCCM Last Policy Request"=strftime('SCCM Last Policy Request',"%m/%d/%Y %H:%M")
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...