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!

Aligning Observability Costs with Business Value: Practical Strategies

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

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...