Date diffrence

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rubbersoul

    #1

    Date diffrence

    I have a table with 3 colums:

    Date (datetime)
    End (datetime)
    Sys_id (INT)

    What I need to do is write a query that will do a calculation and
    return the diffrence in hours between date and end. I though that
    maybe a DATE_SUB would work but I can't seem to get it to do as I
    want. Hope someone can help.
  • 2metre

    #2
    Re: Date diffrence

    rubbersoul wrote:[color=blue]
    > I have a table with 3 colums:
    >
    > Date (datetime)
    > End (datetime)
    > Sys_id (INT)
    >
    > What I need to do is write a query that will do a calculation and
    > return the diffrence in hours between date and end. I though that
    > maybe a DATE_SUB would work but I can't seem to get it to do as I
    > want. Hope someone can help.[/color]
    Subtract the UNIX timestamps and that will give you the difference in
    seconds.

    Comment

    • 2metre

      #3
      Re: Date diffrence

      2metre wrote:[color=blue]
      > rubbersoul wrote:
      >[color=green]
      >> I have a table with 3 colums:
      >>
      >> Date (datetime)
      >> End (datetime)
      >> Sys_id (INT)
      >>
      >> What I need to do is write a query that will do a calculation and
      >> return the diffrence in hours between date and end. I though that
      >> maybe a DATE_SUB would work but I can't seem to get it to do as I
      >> want. Hope someone can help.[/color]
      >
      > Subtract the UNIX timestamps and that will give you the difference in
      > seconds.[/color]

      or for hours rounded to the nearest.. (have tested this!)

      select
      Sys_id,
      round((UNIX_TIM ESTAMP(End)-UNIX_TIMESTAMP( Date))/3600)
      from
      tablename

      Comment

      • rubbersoul

        #4
        Re: Date diffrence

        2metre <2metre@xxxhers ham.net> wrote in message news:<cmdr69$lo 9$1@titan.btint ernet.com>...[color=blue]
        > 2metre wrote:[color=green]
        > > rubbersoul wrote:
        > >[color=darkred]
        > >> I have a table with 3 colums:
        > >>
        > >> Date (datetime)
        > >> End (datetime)
        > >> Sys_id (INT)
        > >>
        > >> What I need to do is write a query that will do a calculation and
        > >> return the diffrence in hours between date and end. I though that
        > >> maybe a DATE_SUB would work but I can't seem to get it to do as I
        > >> want. Hope someone can help.[/color]
        > >
        > > Subtract the UNIX timestamps and that will give you the difference in
        > > seconds.[/color]
        >
        > or for hours rounded to the nearest.. (have tested this!)
        >
        > select
        > Sys_id,
        > round((UNIX_TIM ESTAMP(End)-UNIX_TIMESTAMP( Date))/3600)
        > from
        > tablename[/color]


        This works but dosen't return what I need.

        ----+---------------------+-------------+--------------------
        16 | 2004-10-11 08:05:00 | Problem | 2004-10-11 09:00:00
        16 | 2004-12-12 13:00:00 | Problem | 2004-12-14 15:00:00


        I tried running your query and I got this:


        +--------+---------------------------------------------------------+
        | sys_id | round((unix_tim estamp(end) -unix_timestamp( date))/3600) |
        +--------+---------------------------------------------------------+
        | 16 | 1 |
        | 16 | 50 |
        +--------+---------------------------------------------------------+

        I know this is what I initally asked for but I need the first row to
        come out as 0.55 for the minutes. Sorry....I don't know if this is as
        easy as just removing the round, but I doubt it!

        Comment

        • Wouter

          #5
          Re: Date diffrence

          remove the word

          round

          ...

          "rubbersoul " <rgalley@vacv.c om> wrote in message
          news:f0175b31.0 411050726.7cc1f 9f9@posting.goo gle.com...
          : 2metre <2metre@xxxhers ham.net> wrote in message
          news:<cmdr69$lo 9$1@titan.btint ernet.com>...
          : > 2metre wrote:
          : > > rubbersoul wrote:
          : > >
          : > >> I have a table with 3 colums:
          : > >>
          : > >> Date (datetime)
          : > >> End (datetime)
          : > >> Sys_id (INT)
          : > >>
          : > >> What I need to do is write a query that will do a calculation and
          : > >> return the diffrence in hours between date and end. I though that
          : > >> maybe a DATE_SUB would work but I can't seem to get it to do as I
          : > >> want. Hope someone can help.
          : > >
          : > > Subtract the UNIX timestamps and that will give you the difference in
          : > > seconds.
          : >
          : > or for hours rounded to the nearest.. (have tested this!)
          : >
          : > select
          : > Sys_id,
          : > round((UNIX_TIM ESTAMP(End)-UNIX_TIMESTAMP( Date))/3600)
          : > from
          : > tablename
          :
          :
          : This works but dosen't return what I need.
          :
          : ----+---------------------+-------------+--------------------
          : 16 | 2004-10-11 08:05:00 | Problem | 2004-10-11 09:00:00
          : 16 | 2004-12-12 13:00:00 | Problem | 2004-12-14 15:00:00
          :
          :
          : I tried running your query and I got this:
          :
          :
          : +--------+---------------------------------------------------------+
          : | sys_id | round((unix_tim estamp(end) -unix_timestamp( date))/3600) |
          : +--------+---------------------------------------------------------+
          : | 16 | 1 |
          : | 16 | 50 |
          : +--------+---------------------------------------------------------+
          :
          : I know this is what I initally asked for but I need the first row to
          : come out as 0.55 for the minutes. Sorry....I don't know if this is as
          : easy as just removing the round, but I doubt it!


          Comment

          Working...