Adding to Al’s suggestion…
When you then need to query the database for completed cycles, you can use your database’s window aggregate functions to give you the deltas. For example, in Postgres, it’d look something like this:Select t_stamp, deltaweight
From (
Select t_stamp, weight - lead(weight) over (order by t_stamp desc) as deltaweight
From grouptable
Order By t_stamp Desc
Limit 2) grouptabledelta
Limit 1;
Note that lead() and lag() are based on the row order involved. Since this query looks at the rows in reverse so the limit clause works right, the expressions uses lead() instead of lag(). Anyways, this approach works well for anything that records non-resetting values, including timestamps.
Oh, and you need to use a real database. MySQL can’t do this. Pretty much all the others can.