How Grafana's Yesterday Preset Works

Grafana

When I set the time picker in Grafana to Yesterday, I noticed something curious: both the From and To fields were set to the same value — now-1d/d. How could the same expression define both the start and end of a time range? Curious, I dug into the documentation and source code to understand how this works.

Turns out that Grafana’s relative time syntax uses a /unit rounding operator that is context-sensitive. When used in the From field it floors to unit start, when used in the To field it ceils to unit end.

So when using now-1d/d in the From field, now-1d means “now minus 1 day”, and adding /d means “round down to the day boundary”. And using the same now-1d/d in the To field, it also starts with “now minus 1 day”, but the /d means “round up to the day boundary”. All timestamps are based on the dashboard’s configured timezone, so the exact boundaries depend on that setting.

The result: now-1d/d to now-1d/d gives you a complete calendar day.

The official docs mention some other useful expressions:

Grafana time picker showing the fiscal year preset with now-1y/fy

Grafana time picker with the fiscal year preset

Some other interesting things I found:

tech
Social media crashed a bank in a day, agents will do it before we wake up