Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Converting Integet to Time:

Converting Integet to Time:

Scheduled Pinned Locked Moved Database
databasecomtutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shahzad Aslam
    wrote on last edited by
    #1

    Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.

    Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com

    P V 2 Replies Last reply
    0
    • S Shahzad Aslam

      Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.

      Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      I use:

      CREATE FUNCTION [Lib].[IntToTime] (@Subject INT)
      RETURNS DATETIME AS
      BEGIN
      DECLARE @result AS DATETIME
      SET @result = '1970-01-01 00:00:00'

      SET @result = DATEADD ( HH , @Subject/10000 , @result )
      SET @Subject = @Subject - @Subject/10000*10000

      SET @result = DATEADD ( mi , @Subject/100 , @result )
      SET @Subject = @Subject - @Subject/100*100

      SET @result = DATEADD ( ss , @Subject , @result )

      RETURN ( @result )
      END

      Then you can CONVERT the DateTime to string as needed.

      1 Reply Last reply
      0
      • S Shahzad Aslam

        Hi I am trying to convert an integer value to time is it possible in a query to convert? For example a value 130210 stored as int should display as hh:mm:ss format.

        Shahzad Aslam Software Engineer Softech Systems Limited Cell: +92-321-4606036 Email: shehzadaslam@hotmail.com

        V Offline
        V Offline
        Virendrak
        wrote on last edited by
        #3

        declare @sec int set @sec=130210 select convert(varchar(5),@sec/3600)+' Hrs : '+convert(varchar(5),@sec%3600/60)+' Min : '+convert(varchar(5),(@sec%60))+' Sec' OR --If 130210 is Second : SELECT CONVERT(varchar(8), DATEADD(second, 130210 , '0:00:00'), 108) --If 130210 is Minute : SELECT convert (varchar(8),dateadd(minute,130210 ,'0:00:00'),108) OR declare @Diff int set @Diff=130210 SELECT CONVERT(varchar(6), @Diff/3600) + ':' + RIGHT('0' + CONVERT(varchar(2), (@Diff % 3600) / 60), 2) + ':' + RIGHT('0' + CONVERT(varchar(2), @Diff % 60), 2)

        Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups