Splunk Search

How do I localize date_mday?


When I use chart using date_mday as a parameter, it is in GMT. Is there any way to make this the date for my local time zone?

Tags (2)

Super Champion

I don't think you can, at least not easily. The problem is that date_mday and all the other date_* fields are determined at index time. So these are static values that cannot be shifted to adjust for timezone at search time.

You can however build your own field that contains the day with an eval command like this:

 ... | eval mday=strftime("%d", _time) | chart ... by mday

So from there you will probably get the exact same value that date_mday already contains, so what you'll have to do is find the correct timezone offset and adjust for that manually. For example, if are 1 hour off GMT, then you could use:

 ... | eval mday=strftime("%d", _time+3600)

If you have different servers in different timezones that this gets more complicated. You may be able to leverage the fact that date_zone contains the timezone offset in minutes within your timezone calculations. (It also contains the word "local", so'll have to filter that out, something like:

 ... | eval tz_offset_secs=if(date_zone=="local", 0, date_zone*60)

Related question:

0 Karma

Splunk Employee
Splunk Employee

Just to be accurate, if date_zone is local, then the offset you use should be the offset of the indexer's local time zone. This would only be zero if the indexer was running on UTC/GMT, but is fixed and known for any given indexer.