Concatenation of a Select field into the ADDTIME function

Asked

Viewed 45 times

1

"SELECT     at.codigoTurma, "
           "ADDTIME(t.horaInicioCurso, '00:01:00'), "
           "t.toleranciaCurso, "
           "t.horaFinalCurso "
"FROM       AlunosTurmas at "
"INNER JOIN Turmas t "
"ON         t.codigoTurma = at.codigoTurma "
"WHERE      at.matriculaAluno = :matricula "
"ORDER BY   t.horaInicioCurso"

I’d like to use the field t.toleranciaCurso, in function ADDTIME, in place of minutes.

t.tolerancia(INT), t.horaInicioCurso(TIME).
ADDTIME(t.horaInicioCurso, '00:' + t.toleranciaCurso + ':00') // soma apenas segundos
  • And why not use? Gives some error? Any wrong result? What kind are the columns? In case t.toleranciaCurso needs to be the TIME or you need to convert to this type ((STR_TO_DATE)[https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date]). by the column description, it should be of this type. If it is not, there is already a mistake there. Can you fix this? https://dev.mysql.com/doc/refman/5.6/en/date-and-time-type-conversion.html

  • sorry n inform. t. hoursInicioCurso(TIME), t.toleranciaCurso(int). but if I try to put, for example: ADDTIME(t.hoursInicioCurso, '00:'+t.toleranciaCurso+':00) it adds seconds even so

1 answer

1


Since the second parameter of the function ADDTIME() needs to be the TIME and you want to use a dot column type INT need convert with function SEC_TO_TIME():

SEC_TO_TIME(t.toleranciaCurso * 60)

I put in the Github for future reference.

This function expects the number of seconds, as you have minutes, need to convert to this unit of measure in a simple arithmetic.

  • Thank you very much! It worked perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.