Help converting a decimal time in db4 to an actual time in sql server.

  • I am pulling data from an AS400 where the actual time is stored as a decimal (example - 113804 would be 11:38:04 AM, 93804 would 9:38:04 AM) . I need to convert that to an actual time so I can do some comparisons. So the actual data could have a length of 5 or 6. So - any ideas on how to convert this?

    Thanks for the help in advance.

  • declare @input int = 113804

    -- these are the different parts that will be used

    select @input / 10000

    select (@input / 100) % 100

    select @input % 100

    -- SQL Server 2008 Query

    select convert(time, dateadd(ss, @input % 100, dateadd(mi, (@input / 100) % 100, dateadd(hh, @input / 10000, '19000101'))))

    -- SQL Server 2012 Query

    select timefromparts(@input / 10000, (@input / 100) % 100, @input % 100, 0, 0)

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Sweet query - works great! Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply