Problems with Datediff

Hello,

I am using a query from our SQL server to output a date and a difference in days from now. In SQL Management Studio I get the result as I would like it.

However, Grafana makes a date out of the difference value.
What am I doing wrong?

Welcome to the Grafana forums.

Can you post a screenshot of what is shown when you click the button Generated SQL?
image

Hi, the generated SQL is this :

select TOP 1 dErstelltWawi, DATEDIFF(DAY, tbestellung.dErstelltWawi, GETDATE()) AS Differenz from tBestellung
join tZahlungsart on tzahlungsart.kZahlungsart = tbestellung.kZahlungsArt
where tbestellung.kZahlungsArt = 6
order by dErstelltWawi desc

Try casting/converting it in SQL or Setting a Grafana field override?

Hey i´ve tried it before,

but what should i change in the sql ? In the sql management Studio i become just a Number , so how i would.

In Grafana every Override i tried it dont work. If you have an idea for override please let me know

Here I have something similar, maybe that’s what you want

image

Ok it seems to going in the correct way. One Question → Is it possible to give everything in Days out ?

For example on you picture. 3.43 Weeks are aroun25 Days
And all under 24 Hours are 0

I’d say Calculate Days in SQL and set Grafana override to days and decimals to Zero

Tried it there, you might need to set it to a custom unit “Days”

Just look at my First Pictures. I´ll always late the Days calculate in SQL → So the difference ist just one Number in Days.

1 Like