Jump to content
Fórum Script Brasil
  • 0

Problema - Conversor de Data e Horas para Dias


Johnnny

Question

Eu não sei porquê mas quando eu entro com os dados na function, recebo uma mendagen de erro:

Mensagem 102, Nível 15, Estado 1, Linha 1

Incorrect syntax near '1985/04/11'.

Aqui está o script...

Create Function TotalDeHoras(@dt_inicial datetime, @hr_inicial datetime, @dt_final datetime, @hr_final datetime)

Returns int

as

begin

select @dt_inicial = Convert(datetime,@dt_inicial,101),

@hr_inicial = Convert(datetime,@hr_inicial,101),

@dt_final = Convert(datetime, @dt_final,101),

@hr_final = Convert(datetime,@hr_final,101)

declare @dt_total int

set @dt_total = (select datediff(hour, @dt_inicial + @hr_inicial, @dt_final + @hr_final)/24)

Return @dt_total

end

/*

exec TotalDeHoras('1985/04/11', '22:00', '2011/12/09', '16:00')

*/

Desde já eu agradeço ! ABS!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Bom dia Johnnny,

O que está querendo retornar com esta função? Quando você converte apenas horas, o sql por default preenche a data com 1900-01-01....

Fale-me qual o resultado de retorno q deseja q podemos fazer umas adaptações.... rs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...