Using Rails ActiveRecord, am wanting to calculate the time between two datetime fields within the same row. The difference between the two datetimes could be seconds through to hours, and could span mid-night. A number of seconds representing the difference would be dandy.
Am using both sqlite and postgress.
Playing with sqlite, the following just gives 0 for the calculation. (both “solved_at” and “started_at” are type “datetime”, and “solved_at” is later than “started_at”)
SELECT (datetime(solved_at) - datetime(started_at)) FROM "schedules";
something like this: