int to time conversion

  • could any body help me out , i have two columns one is "datetime" which is storing date and other is "int" which is storing time , now i need to club them and compare with system date for one of the procedure , any direction is appreciated.

  • It would help if you could provide the DDL (CREATE TABLE statement) for the table, some sample data, and the expected results based on the sample data.

  • simplest way you can use is like this -

    Example -

    Create Table #Test(dt datetime , tm int)

    Insert into #Test values(getDate(),1)

    Insert into #Test values(getDate(),2)

    Insert into #Test values(getDate(),3)

    Insert into #Test values(getDate(),4)

    Insert into #Test values(getDate(),5)

    Select cast(dt as varchar) + ':' + cast(tm as varchar) From #TEST

    But again it depends what your table structure is and how you storing date and time in the table.

    MJ:cool:

  • What does the time integer represent? Is it 0 - 2359, where 1061 would never exist? 1000 - 2459? Is it the time converted to minutes (hour of day * 60 + minutes past hour)? Time converted to seconds? Please provide more info!

  • Thanks for your reply. sdate in datetime and stime in seconds

    "sdate" "stime"

    "2009-04-18 00:00:00.000" "59002"

    i am not sure how i can really convert and merge both after i convert stime to hours or mins(by dividing 3600 or 60) so i can compare the same with getdate() that gives me correct date and time difference.

    sorry new to this so if asking too many question.

  • Try: DATEADD(ss, stime, sdate)

    (and after trying be sure to lookup "DATEADD" in the Books On-Line!)

  • You rock , that worked ,thanks much.

    thanks to all who responded to help!!

Viewing 8 posts - 1 through 7 (of 7 total)

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