Home > Blockchain >  Number of 30 min intervals between two timestamps
Number of 30 min intervals between two timestamps

Time:05-17

Each row of data has a start and end timestamp. I've round them to the nearest 30 min interval using the time_slice function. Now, I would like to calculate the number of 30 min intervals between the start and end (for each row). Is there some kind of inbuilt function for this or do I need to first convert it to epoch/ unix.

CodePudding user response:

select '01:30'::time as a,
   '13:30'::time as b, 
   timediff('min',a,b) as c, 
   floor(c/30) as d;

gives:

A B C D
01:30:00 13:30:00 720 24

so I would use TIMEDIFF or DATEDIFF and FLOOR the division.

  • Related