Splunk Enterprise

How convert time format

Nraj87
Explorer

Hi ,

 

How to convert 2025-03-13T11:03:38Z to the "%d/%m/%Y %I:%M:%S ".

I have tried this, but it didn't work.

| eval Lastevent=strftime(last_seen, "%d/%m/%Y %I:%M:%S %p")

Labels (1)
Tags (1)
0 Karma

livehybrid
Influencer

Hi @Nraj87 

Check out the following, using makeresults to create a sample event:
livehybrid_0-1742218298466.png
| makeresults count=1
| fields - _time
| eval last_seen="2025-03-13T11:03:38Z"
| eval Lastevent=strftime(strptime(last_seen, "%Y-%m-%dT%H:%M:%SZ"), "%d/%m/%Y %I:%M:%S %p")

The reason your original command didn't work is because:

  1. You need to first parse the input format using strptime
  2. Then convert it to your desired format using strftime

The strptime function tells Splunk how to read the input date format, similarly to the strftime

  • %Y: Full 4 digit Year with century (2025)
  • %m: Month (03)
  • %d: Day (13)
  • T: Literal 'T'
  • %H: Hour in 24-hour format (11)
  • %M: Minute (03)
  • %S: Second (38)
  • Z: Literal 'Z' for UTC timezone

If you want to include AM/PM, keep the %p in the output format. If you don't need it, you can remove it - although you may wish to use %H to return 24hour format instead of %I for 12 hour format.

Please let me know how you get on and consider adding karma to this or any other answer if it has helped.
Regards

Will

 

0 Karma

kiran_panchavat
Influencer

@Nraj87 

| makeresults 
| eval last_seen = "2025-03-13T11:03:38Z"
| eval Lastevent = strftime(strptime(last_seen, "%Y-%m-%dT%H:%M:%SZ"), "%d/%m/%Y %I:%M:%S %p")

kiran_panchavat_0-1742214234290.png

 

I hope this helps, if any reply helps you, you could add your upvote/karma points to that reply, thanks.

ITWhisperer
SplunkTrust
SplunkTrust

Is last_seen a string? If so, try parsing it to convert it to an epoch time before formatting the result back to a different string.

| eval Lastevent=strftime(strptime(last_seen, "%FT%T%Z"), "%d/%m/%Y %I:%M:%S %p")
0 Karma
Get Updates on the Splunk Community!

Splunk Observability Synthetic Monitoring - Resolved Incident on Detector Alerts

We’ve discovered a bug that affected the auto-clear of Synthetic Detectors in the Splunk Synthetic Monitoring ...

Video | Tom’s Smartness Journey Continues

Remember Splunk Community member Tom Kopchak? If you caught the first episode of our Smartness interview ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud? Learn how unique features like ...