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!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

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 ...