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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...