I have a grafana chart showing the data of the last 24 hours
But the data does not fit the time axis. There is missing 2 hours in the beginning of the 24 hour period. And the last value at 21:27:57 is 66.74 but at this time it was 73.50.
The time axis seems to be shifted by 2 hours. The data at time x shows the data of time x-2h.
The timestamp (datetime) in the SQL database is correct.
EDIT:
Changing the timezone doesn't help much. Using UTC (which is wrong for me) the most recent time on the time axis is about 20:40 (wrong)
Using UTC+2 (which fits my timezone) the most recent time is about 22:40, the correct local time when taking the screenshot.
The data is not affected and there is still 2 hours missing in the 24 hour period. And still the most recent value in the chart shows the value of 2 hours ago.
I don't really understand why, but I figured out that there is a UNIX_TIMESTAMP() needed:
SELECT
UNIX_TIMESTAMP(timestamp) AS "time",
humidity
FROM Sensor_BME280_01
WHERE
$__timeFilter(timestamp)
ORDER BY timestamp
instead of
SELECT
timestamp AS "time",
humidity
FROM Sensor_BME280_01
WHERE
$__timeFilter(timestamp)
ORDER BY timestamp
The value timestamp is of type DATETIME in a MariaDB.
Related
I am trying to calculate the difference in seconds between 2 dates in hive. I found that one of the records is being calculated incorrectly, and I can't understand why or how to fix it.
The example is as follows:
select '2020-03-08 03:00:48' as stop_time,
UNIX_TIMESTAMP('2020-03-08 03:00:48') as stop_timestamp,
'2020-03-08 02:45:03' as start_time,
UNIX_TIMESTAMP('2020-03-08 02:45:03') as start_timestamp,
UNIX_TIMESTAMP('2020-03-08 03:00:48') - UNIX_TIMESTAMP('2020-03-08 02:45:03') as difference
I am getting a result of -2,655 instead of +945
Any advise?
Thank you!
This happens because of daylight savings time change. The place where you're located has day lights savings time that changed during 8 March, 2020 at the same hour. So, it is calculating different timestamp for start_timestamp.
I need to find the 7 day rolling average of the temperature.
Using date strings provided in my dataset, I created a unix timestamp. I substituted the first time stamp on each day with the associated unix timestamp on midnight of that day.
There are 604800 unix seconds in one week, so I tried using the following code to calculate it, but it did not work. How can I fix this code so it performs the window calculation correctly?
DROP VIEW IF EXISTS every_7_days;
CREATE VIEW every_7_days AS
SELECT weather_dt,
time,
fixed_unix_time,
temperature,
avg(temperature) OVER(ORDER BY fixed_unix_time RANGE BETWEEN 604800 PRECEDING AND CURRENT ROW) AS roll7day_avg
FROM clean_first_row
ORDER BY fixed_unix_time;
I would like to check if the processed date is today.
xsl:if test="ProcessedDate = 'Today'" won't work since the value of processed date is a timestamp more like 2016-06-07T09:06:54.827z
How can I mathematically convert it to check the processed date to see if it's in the past 24 hrs.
Perhaps within a ().
i have a lot of data that has at start time and a finnish time. These are formated i datetime format.
i want to sum the time that occurs in an timeinterval
if specify the time interval 08-11
i only want to get the time between these to even if the evvent progresses from 06 to 12
If you are using SQL Server you could do it like that:
SELECT SUM(DATEDIFF(HOUR,StartTimeColumn,EndTimeColumn)) AS ElapsedHoursTotal,
SUM(DATEDIFF(MINUTE,StartTimeColumn,EndTimeColumn)) AS ElapsedMinutesTotal,
SUM(DATEDIFF(SECOND,StartTimeColumn,EndTimeColumn)) AS ElapsedSecondsTotal,
FROM dbo.YourTable
You will have to find the perfekt interval (First Parameter of DATEDIFF Function) for your requirements... Hours, Minutes, Seconds, Nanoseconds,...
Im using mssql 2012
the problem is that i can get the full elapsed time from start to finnish but I only want the part that matches my search
if the pattern i match for is 8-11
thing one 08-12 should produce 3 hours
thing two 10-11 should produce 1 hour
thing tre 9.30- 14 shoud produce 1.5 hour
I have a table described here: http://sqlfiddle.com/#!3/f8852/3
The date_time field for when the time is 00:00 is wrong. For example:
5/24/2013 00:00
This should really be:
5/23/2013 24:00
So hour 00:00 corresponds to the last hour of the previous day (I didn't create this table but have to work with it). Is there way quick way when I do a select I can replace all dates with 00:00 as the time with 24:00 the previous day? I can do it easily in python in a for loop but not quite sure how to structure it in sql. Appreciate the help.
All datetimes are instants in time, not spans of a finite length, and they can exist in only one day. The instant that represents Midnight is by definition, in the next day, the day in which it is the start of the day, i.e., a day is closed on its beginning and open at its end, or, to phrase it again, valid allowable time values within a single calendar date vary from 00:00:00.00000, to 23:59:59.9999.
This would be analogous to asking that the minute value within an hour be allowed to vary from 1 to 60, instead of from 0 to 59, and that the value of 60 was the last minute of the previous hour.
What you are talking about is only a display issue. Even if you could enter a date as 1 Jan 2013 24:00, (24:00:00 is not a legal time of day) it would be entered as a datetime at the start of the date 2 Jan, not at the end of 1 Jan.
One thing that illustrates this, is to notice that, because of rounding (SQL can only resolve datetimes to within about 300 milleseconds), if you create a datetime that is only a few milleseconds before midnight, it will round up to midnight and move to the next day, as can be seen by running the following in enterprise manager...
Select cast ('1 Jan 2013 23:59:59.999' as datetime)
SQL server stoers all datetimes as two integers, one that represents the number days since 1 Jan 1900, and the other the number of ticks (1 tick is 1/300th of a second, about 3.33 ms), since midnight. If it has been zero time interval since Midnight, it is stll the same day, not the previous day.
If you have been inserting data assuming that midnight 00:00:00 means the end of the day, you need to fix that.
If you need to correct your existing data, you need to add one day to every date in your database that has midnight as it's time component, (i.e., has a zero time component).
Update tbale set
date_time = dateAdd(day, 1, date_time)
Where date_time = dateadd(day, datediff(day, 0, date_time), 0)