Dashboard variable : MySQL datetime

Hello everyone, I’ma facing an issue while using a DATETIME var as a dashboard variable.

The var type is DATETIME so like this : YYYY-M-DD HH:MinMin:SecSec and I select it as a dashboard variable which end up as a really long number instead of date format.

I don’t know yet how to make it have a date format.

image

look into using from_unixtime function to return that epoch to human readable value

Thanks for this useful info ! Infortunately it doesn’t seem to return anything…I tried different ways yet nothing worked :confused:

I tried these :
→ from_unixtime(${date}) so using the dashboard variable hat was returning the number list
→ from_unixtime(number) directly using the number returned by the variable date
→ from_unixtime(${date}, ‘%Y.%m.%d.%H.%i.%s’) specifying the format

And in the end it didn’t return any value

try dividing that number by 1000 I think.

1 Like

I was about to tell you that, well done yes it’s better now !!

There still is an issue…I have a dashboard variable “date” which returns something like “1729251541” that I use in another dashboard variable “DATE” that looks like this
→ FROM_UNIXTIME(SUBSTR( 1729251541000, 1, 10), ‘%Y-%m-%d %H:%i:%s’

This way i can only return one value for DATE which is’nt my goal, and if I mix the two variable to make one it returns 2 values that are incorrect (year 1970 and only 2).

your question is more mysql than grafana.
this looks very problematic

FROM_UNIXTIME(SUBSTR( 1729251541000, 1, 10)

doing substrings on epochs, why? anyways, best to post in a mysql forum for this question in my opinion.

I get why you’re saying this however when trying this in my database the line FROM_UNIXTIME(SUBSTR( 1729251541000, 1, 10), ‘%Y-%m-%d %H:%i:%s’) works perfectly !

The time data I use on Grafana in the dashoard variable “date” is write like this 2024-10-18 13:39:01 in my database but when I select it as a dashboard variable it becomes epochs that is my main issue I guess.

And doing substrings on epochs because it is actually 3 numbers longer than the regular writing.

so in your variable configuration use FROM_UNIXTIME

here is the same issue in ms sql server

variable set up

as you can see, the variable value is epoch when using raw GETUTCDATE()

and here it is when I add the convert function (which I do not know what it is in mysql)

so fix the variable so it returns exactly the date format needed by your query.

1 Like

Okay that’s better now, I appreciate your help !!

So this might seem foolish but I did this and it works really well.

image

And it returns this

1 Like