Skip to Content

convertir campo hora

Hola expertos, estoy tratando de convertir un campo de "Hora" pero me muestra un error: Conversion failed when converting date and/or time from character string

SELECT

case len (t0.createtime)

when 3 then convert(time,substring(convert(nvarchar,t0.createtime),1,1)

+':'+ substring(convert(nvarchar,t0.createtime),2,2))

when 4 then convert(time,substring(convert(nvarchar,t0.createtime),1,1)

+':'+ substring(convert(nvarchar,t0.createtime),2,2))

end

FROM OSCL T0

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 30, 2015 at 04:38 PM

    Hola Oscar, yo tengo algo similar en Crystal Reports para mostrar la hora en formato hora. Igual de aquí sacas una idea:

    If Len(cstr({OPDN.U_HoraPesoBruto},'#')) = 4 Then

        left(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ":" + Right(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ' Hrs'

    else

        left(cstr({OPDN.U_HoraPesoBruto},'#'),1) + ":" + Right(cstr({OPDN.U_HoraPesoBruto},'#'),2) + ' Hrs'

    Suerte.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 30, 2015 at 04:42 PM

    Oscar,

    Intenta con esto:

    SELECT
    convert(time,left(right('0000' + createtime, 4), 2) + ':' + right(right('0000' + createtime, 4), 2)) [Hora]
    FROM OSCL T0
    

    Saludos y suerte,

    JC.

    Add comment
    10|10000 characters needed characters exceeded