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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...