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!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...