Splunk Search

How do I get the 1st day on the current year ?

Clovisa
Path Finder

Hello, I would like to visualize data starting from the 1st of January of the current year.
I see how to get the current year, but how can we combine it with "1st of January" ?

index=main | eval year=strftime(now(),"%Y") 
Tags (2)
0 Karma
1 Solution

cmerriman
Super Champion

if you're looking to search for data year-to-date, use index=main earliest=@y

if you are looking to do year-roll-ups, you can do things like index=main|timechart span=1y count

you can format the time with |eval _time=strftime(relative_time(_time,"@y"),"%Y-%m-%d") to make all timestamps group to January 1 of that year in YYYY-mm-dd timestamp.

View solution in original post

somesoni2
Revered Legend

Whats your report requirement and what's the query you're using?

0 Karma

cmerriman
Super Champion

if you're looking to search for data year-to-date, use index=main earliest=@y

if you are looking to do year-roll-ups, you can do things like index=main|timechart span=1y count

you can format the time with |eval _time=strftime(relative_time(_time,"@y"),"%Y-%m-%d") to make all timestamps group to January 1 of that year in YYYY-mm-dd timestamp.

Clovisa
Path Finder

Thanks, the first option does exactly what I wanted !

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...