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!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...