Splunk Search

How to get last login from multiple date ?

riposan
Explorer

please help,i used _time from date log, and i using time from windowstime, but i tried substraction bot of them not result in coloumn durationday

 

stats max(_time) as lastlogin by user |eval n=time()|eval today=strftime(n,"%m-%d-%Y %H:%M:%S.%Q")| eval durationday = lastlogin - today | table user,lastlogin,today,durationday

 

and result this

user lastlogin today durationday

dsadadnk1201-30-2023 11:10:27.20801-30-2023 11:25:14.000 
Labels (1)
0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @riposan,

You should calculate the duration before formatting the lastlogin. Please try below;

| stats max(_time) as lastlogin by user 
| eval n=time() 
| eval durationday = n-lastlogin 
| eval today=strftime(n,"%m-%d-%Y %H:%M:%S.%Q") 
| eval durationday= tostring(durationday,"duration") 
| table user,lastlogin,today,durationday
If this reply helps you an upvote and "Accept as Solution" is appreciated.

riposan
Explorer

thx for reply my question. i tried this,still no result in coloumn durationday

0 Karma

riposan
Explorer

after i tried change coloumn _time, its still work. thx

0 Karma
Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Building Momentum: Splunk Developer Program at .conf25

At Splunk, developers are at the heart of innovation. That’s why this year at .conf25, we officially launched ...