1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Calculate time difference in PSQL with HH:MM splitted in several columns

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 27, 2021.

  1. Stack

    Stack Membro Participativo

    I've a PSQL table like this:

    Order Start_Hour Start_Minute Finish_Hour Finish_Minute
    10 10 15 12 15
    10 12 15 14 15
    10 16 00 17 00

    And I need to calculate by a query the total time expressed in hours that I spent to finish the order. In this scenario I expect to have a total of 5 hours:

    12:15 - 10:15 = 2 hours
    14:15 - 12:15 = 2 hours
    17:00 - 16:00 = 1 hours


    The query result must be 5.

    The idea was concatenate start hour/minute and finish hour/minute, convert them to hour, make the difference, calculating the total.

    SELECT (Start_Hour & ":" & Start_Minute) as start, (Finish_Hour & ":" & Finish_Minute) as finish

    FROM OrderDetails


    But when I try to convert them to HH:MM using cast or convert but I got errors.

    Any advice? Thank you

    Continue reading...

Compartilhe esta Página