Query Max / Min Value in InfluxDB between now and the start of day

Hello,

I’m recording the temperature of my house in the Influx DB database and I would like to know, during the day, the MAX and MIN value between the start of day until now ( and now to use now - 1day).
But the time operator “start of day” doesn’t exist in InfluxDB, but I can see this value on grafana, and I tell me that is possible to do that but why .
Could you help me please ?

Thank you !

Anyone can help me ?

How are you defining start of day? Do you mean since 12:00:00 or now() - 1d ?

In flux you can simply add the function |> min() to your query to get the min, and likewise the call to |> max() to get the max for the same window.

in InfluxQL SELECT max("temp_c") AS "max_temp_c" FROM "telegraf"."autogen"."environment" WHERE time > :dashboardTime: GROUP BY time(:interval:)

Should do it (you’ll have to adjust for your measurements and fields, of course.

dg

In fact, I would like to get the max and min value, in InfluxDB base (temperature), since the start of day, which means, since for today in example 2019/11/21 at 00:00:00 until now.

Thank you for your help

Hi weado, sorry to resurrect this old post, but i’m trying to do something practically the same as you but for outdoor temperatures measurements in influx.

I don’t know about you, but I’m using influxdb on linux, in which case you can do some magic in bash like via a bash script to do what you’re trying to achieve.

My bash code, put into a file like minmax.sh:

#!/bin/bash
#Assign the current date to a variable
datetime=$(date -Id)
#Add time 00:00 to the variable
datetime="${datetime}T00:00:00Z"
#Spit back out the target date/time to check
#echo $datetime

#Query influx for the data
influx -precision rfc3339 -database airpressure -execute "SELECT MIN("value") AS "min_temp_c" FROM outtemp WHERE time <= now() AND time >= '$datetime'"
1 Like

Also for windows a batch script could be used (.cmd/.bat file), with the following code:

@echo off
set month=%date:~3,2%
set day=%date:~0,2%
set year=%date:~6,4%
rem echo %year%-%month%-%day%T00:00:00Z
set datetime=%year%-%month%-%day%T00:00:00Z
echo %datetime%

influx -precision rfc3339 -database airpressure -execute "SELECT MIN("value") AS "min_temp_c" FROM outtemp WHERE time <= now() AND time >= '%datetime%'"
1 Like