Skip to Content
author's profile photo Former Member
Former Member

Diferencia minutos entre Doctime y hora actual

Buenos dias

Necesito encontrar la diferencia entre el campo doctime de la tabla ORDR y la hora actual del sistema

He utilizado la funcion Datediff pero no me funciona

El select que estoy utilizando es:

select doctime,CONVERT(VARCHAR,GETDATE(), 108) 'hora actual',datediff(mm, CONVERT(VARCHAR,GETDATE(), 108),doctime) 'diferencia'

FROM Ordr T0

where docdate=CONVERT(VARCHAR,GETDATE(), 103)

El resultado que arroja es

doctime hora actual diferencia

9:18AM 09:18:29 30

la diferencia para el caso anterior deberia ser 0 (cero) y no 30

¿Alguien sabe como hallar esta diferencia?

Muchas gracias a quien pueda ayudarme

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2015 at 06:40 PM

    Fátima,

    El problema es que DocTime no es dato de tiempo, sino numérico. Necesitarías convertirlo a tipo hora para hacer el cálculo que necesitas. Intenta con esto haber qué te parece:

    select doctime,CONVERT(VARCHAR,GETDATE(), 108) 'hora actual',
         datediff(mi
           , left(convert(time,getdate(),108),8)
           , left((right('0000' + convert(nvarchar(4),DocTime),4) + '00' ),2) + ':' + right(doctime,2)
           ) [Diferencia]
    FROM Ordr T0
    where docdate=CONVERT(date,GETDATE(), 103)  
    
    
    

    Saludos,

    JC.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.