Button to set time range

I’d like to have a button to
If current time between 6am and 6pm, set time range to 6am-6pm.
If current time between 6pm and 6am, set time range to 6pm-6am.
This would allow someone to view an entire “current” shift window.

Anyone got a solution to something like this?

Have you seen this post?

You can use the “Timepicker Buttons Panel” Plugin
As an example for an sql staement:

DECLARE @currentHour INT = DATEPART(HOUR, GETDATE());
DECLARE @time_window NVARCHAR(50);
DECLARE @time_from DATETIME;
DECLARE @time_to DATETIME;

IF @currentHour >= 6 AND @currentHour < 18
BEGIN
– Zeitfenster von 6 Uhr bis 18 Uhr heute
SET @time_from = DATEADD(HOUR, 6, CAST(CAST(GETDATE() AS DATE) AS DATETIME)); – 6 Uhr heute
SET @time_to = DATEADD(HOUR, 18, CAST(CAST(GETDATE() AS DATE) AS DATETIME)); – 18 Uhr heute
SET @time_window = ‘6h - 18h’;
END
ELSE
BEGIN
– Zeitfenster von 18 Uhr bis 6 Uhr
IF @currentHour < 6
BEGIN
– Zeitfenster von 18 Uhr des vorherigen Tages bis 6 Uhr heute
SET @time_from = DATEADD(HOUR, 18, DATEADD(DAY, -1, CAST(CAST(GETDATE() AS DATE) AS DATETIME))); – 18 Uhr gestern
SET @time_to = DATEADD(HOUR, 6, CAST(CAST(GETDATE() AS DATE) AS DATETIME)); – 6 Uhr heute
END
ELSE
BEGIN
– Zeitfenster von 18 Uhr heute bis 6 Uhr morgen
SET @time_from = DATEADD(HOUR, 18, CAST(CAST(GETDATE() AS DATE) AS DATETIME)); – 18 Uhr heute
SET @time_to = DATEADD(HOUR, 6, DATEADD(DAY, 1, CAST(CAST(GETDATE() AS DATE) AS DATETIME))); – 6 Uhr morgen
END
SET @time_window = ‘18h - 6h’;
END

SELECT
CONVERT(BIGINT, DATEDIFF(SECOND, ‘1970-01-01’, @time_from)) * 1000 AS ‘time_from’,
CONVERT(BIGINT, DATEDIFF(SECOND, ‘1970-01-01’, @time_to)) * 1000 AS ‘time_to’,
@time_window AS ‘time_window’

works like a charm

1 Like

what is your datasource?

you could also do it using conditional querying in your datasource.

I didn’t find this one. Thanks I’ll take a look :slight_smile:

Beauty! I shall study this and give it a try. Thanks!

I’m using InfluxDb

are you using influxql or flux query language?

Using Flux

Can you check for those date time ranges using conditional logic and return required data accordingly?

Then add a Refresh interval of 5min or so and dashboard will refresh with 0 hutton

import "date"
startDateTime = make it today 6am
currentDateTime = now() or system.time()


date.add(d: 6h, to: 2019-09-16T12:00:00Z)

If currentDateTime between 

If currentDateTime between

Etc