I have a single time-series table with some data, but the time-stamp is occasionally off. To check the timestamp, we have been manually defining sunrise and sunset to get an estimate of solar noon using the PAR (Photosynthetically Active Radiation) values - PAR tells how much light is coming in - to determine daybreak and nightfall, then extrapolate solar noon at the midpoint between the two. We decided to declare that the record where PAR rises above 1.9, usually about 7AM, is daybreak, and the record where PAR is equal to or less than 1.9 is considered nightfall.
I've selected the PAR values above 1.9, and then find the min and max time values for each day using a GROUP BY, and this works:
SELECT datePart, MIN(timePart) AS sunrise,
MAX(timePart) as sunset,
TIMEDIFF(MAX(timePart),
MIN(timePart)) AS dayHours FROM
Imnavait101119_110225
WHERE PAR_2029410_uE
>1.9
GROUP BY datePart
I get this (yes, it's correct, it's an arctic site).
datePart sunrise sunset dayHours dayHoursHalf
07/09/2010 0:07:00 23:52:00 23:45:00 NULL
07/10/2010 0:07:00 23:52:00 23:45:00 NULL
07/11/2010 0:07:00 23:22:00 23:15:00 NULL
07/12/2010 1:37:00 23:52:00 22:15:00 NULL
07/13/2010 0:07:00 23:52:00 23:45:00 NULL
07/14/2010 0:07:00 23:52:00 23:45:00 NULL
07/15/2010 0:07:00 23:52:00 23:45:00 NULL
07/16/2010 0:07:00 23:52:00 23:45:00 NULL
07/17/2010 0:07:00 23:52:00 23:45:00 NULL
07/18/2010 0:07:00 23:52:00 23:45:00 NULL
07/19/2010 0:22:00 23:52:00 23:30:00 NULL
07/20/2010 0:07:00 23:52:00 23:45:00 NULL
07/21/2010 0:07:00 23:52:00 23:45:00 NULL
Now that I have the TIMEDIFF value, I want to divide this value by 2 to add to sunrise to get solar noon. I created a column to hold the value, but can't seem to figure out how to get it. I've been able to divide by 2 or multiply by 0.50, but get very weird results, usually along these lines
SELECT @dayHoursHalf := (dayHours * 0.50) as dayHoursHalf
FROM Imnavait101119_110225_TimestampCheck
and I get this:
dayHoursHalf
117250
117250
115750
110750
117250
117250
117250
117250
117250
117250
116500
117250
117250
117250
I don't even know where to start - these numbers make no sense to me, and I can't find anything about how to code a query for a fractional time value.
Many thanks to all responders.