How to use ${__to:date} without milliseconds?

Hey there!

I’m currently trying to implmenet some stats from our external Mail Security Relay service through its REST API.

It’s going pretty well so far, but I’m facing one issue.

The API expects two keys in the HTTP POST JSON request body, date_from and date_to.
The values of said keys must be in the format YYYY-MM-DDThh:mm:ssZ. So 2025-03-25T00:00:00Z for example.
So far so easy.

In order to request that API, I’m using the Infinity Data Source.
So I tried to just use ${__to:date} and ${__from:date} because that returns an ISO-8601 string, which should be exactly what I need.

However, Grafana will also include milliseconds when doing it that way.

… and the API doesn’t like this.

So I tried to build the string manually via ${__to:date:YYYY-MM-DDThh:mm:ssZ}
But than, Grafana will take the Z character and turns it into my actual timezone difference, being +01:00.

Okay, so I escaped the Z - And now it looks perfect!

However … I can’t escape the Z character once I move this whole theory over to the request body in Infinity, because the escape character \ is invalid.

So … Any ideas on how to solve this?
Would be amazing to get some ideas of you smart people out there!

Thanks :slight_smile:

Hi,

I’m not sure if I’m following correctly (always had problem with dates :smile:) but would something like this work:
${__timeFrom:date:YYYY:MM:DD:hh:mm:ssZ}
__timFrom is Infinity Plugin’s macro added in some version and from some tests of mine they send something like you’re after (I think at least).

1 Like

or just move the Z out of format specifier :slight_smile: LOL "${__to:date:YYYY-MM-DDThh:mm:ss}Z

1 Like