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.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...